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

==========================成功================================

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);

}


}


叶子
浏览 2886回答 1
1回答

botao555

你的servlet的映射是使用注解的方式实现的,不需要再web.xml中配置了。比如你看LoginSuccess 类的开始的地方有个 @WebServlet("/LoginSuccess") 双引号里的就是你需要映射的url地址,如果你想映射成/loginSuccess,就改成@WebServlet("/loginSuccess") 即可。
打开App,查看更多内容
随时随地看视频慕课网APP