==========================成功================================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") 即可。
添加回答
举报
0/150
提交
取消