这是提交的jsp页
<form action="<%=request.getContextPath() %>/servlet/Loginservlet" method="post">
账号<input type="text" name="username"/><br />
密码<input type="password" name="password"/><br />
<input type="submit" value="登录"/>
</form>
然后这是doPost
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String accountname = request.getParameter("username");
String accountpassword = request.getParameter("password");
if(accountname.equals("admin") && accountpassword.equals("admin")) {
request.getRequestDispatcher(request.getContextPath()+"/success.jsp");
(request.getSession()).setAttribute("name", accountname);
}else {
response.sendRedirect(request.getContextPath()+"/login.jsp");
}
}
我用的 @WebServlet("/LoginServlet") 自动注解 就没有直接配置web.xml
如果把注解注释了 手动配置web。xml就会tomcat都启动不了
yanrun
大咪
相关分类