输入正确的用户名和密码后出现HTTP Status 405 - HTTP method GET is not supported by this URL
//LoginServlet.java代码 package com.cj.view;
import javax.servlet.*; import javax.servlet.http.*;
import java.io.*;
public class LoginServlet extends HttpServlet { public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{ response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); out.println("<h1>用户登录</h1>"); out.println("<form action='/UsersManger1/LoginCLServlet' method='POST'>"); out.println("用户名<input type='text' name='username' /><br>"); out.println("密 码<input type='password' name='password' /><br>"); out.println("<input type='submit' value='登录' /><br>"); out.println("</form>");
}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
this.doGet(request, response);
}
}
//LoginCLServlet.java的代码 package com.cj.contraler;
import javax.servlet.*; import javax.servlet.http.*;
import java.io.*;
/** * Servlet implementation class LoginCLServlet */ public class LoginCLServlet extends HttpServlet { public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
response.setContentType("text/html;charset=utf-8"); PrintWriter out = response.getWriter(); String username=request.getParameter("username"); String password=request.getParameter("password");
System.out.print(username+" " +password); if("abc".equals(username)&&"123456".equals(password)) response.sendRedirect("/UsersManger1/MainFrame"); else response.sendRedirect("/UsersManger1/LoginServlet");
} public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
this.doGet(request, response);
}
}
//MainFrame.java的代码 package com.cj.view; import javax.servlet.*; import javax.servlet.http.*;
import java.io.*;
public class MainFrame extends HttpServlet{ public void doGet(HttpServletResponse request,HttpServletResponse response) throws ServletException,IOException{
response.setContentType("text/html;charset=utf-8"); PrintWriter out = response.getWriter(); out.println("<h1>主界面 </h1>");
}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
this.doGet(request, response);
}
}
|