为了账号安全,请及时绑定邮箱和手机立即绑定

创建LoginFail 和LoginSuccess后将URL设置为/loginSuccess /loginFail 在哪里设置 大神 详解 谢了

创建LoginFail 和LoginSuccess后将URL设置为/loginSuccess /loginFail 在哪里设置 大神 详解 谢了

叶子 2016-12-02 10:33:02
==========================成功================================package com.servlet;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;/** * Servlet implementation class LoginSuccess */@WebServlet("/LoginSuccess")public class LoginSuccess extends HttpServlet { protected void processRequest(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException{ response.setContentType("text/html;charset=gbk"); PrintWriter out =response.getWriter(); try{ out.println("<html>"); out.println("<head>"); out.println("<title>登陆成功</title>"); out.println("<body>"); out.println("<h1>登陆成功</h1>"); out.println("<body>"); out.println("<html>"); }finally{ out.close(); } }          /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub processRequest(request,response); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub processRequest(request,response); }}===========================失败===============================package com.servlet;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;/** * Servlet implementation class LoginFail */@WebServlet("/LoginFail")public class LoginFail extends HttpServlet { protected void processRequest(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException{ response.setContentType("text/html;charset=gbk"); PrintWriter out =response.getWriter(); try{ out.println("<html>"); out.println("<head>"); out.println("<title>登陆失败</title>"); out.println("<body>"); out.println("<h1>登陆失败!请重新登录</h1>"); out.println("<body>"); out.println("<html>"); }finally{ out.close(); } }           /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub processRequest(request,response); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub processRequest(request,response); }}
查看完整描述

1 回答

?
botao555

TA贡献48条经验 获得超46个赞

你的servlet的映射是使用注解的方式实现的,不需要再web.xml中配置了。

比如你看LoginSuccess 类的开始的地方有个 @WebServlet("/LoginSuccess") 双引号里的就是你需要映射的url地址,如果你想映射成/loginSuccess,就改成@WebServlet("/loginSuccess") 即可。

查看完整回答
反对 回复 2017-05-09
  • 1 回答
  • 0 关注
  • 2885 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信