servlet配置文件web.xml中<url-pattern>的问题?
项目名:ServletDemoservlet文件:packagecom.servlet.session.Demo2;publicclassLoginServletexte...
项目名:ServletDemo servlet文件: package com.servlet.session.Demo2; public class LoginServlet extends HttpServlet { public LoginServlet(){ super(); } public void destory(){ super.destroy(); } public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{ doPost(request,response); } public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{ String username = request.getParameter("username"); String passwd = request.getParameter("passwd"); if(username.equals("jb-aptech")&&passwd.equals("12345")){ HttpSession session= request.getSession(true); session.setAttribute("username", username); session.setAttribute("passwd", passwd); RequestDispatcher view = request.getRequestDispatcher("InfoServlet"); view.forward(request, response); }else{ response.sendRedirect("../login.jsp"); } } public void init() throws ServletException{ } } jsp文件: <%@ page language="java" import="java.util.*" pageEncoding="gbk"%> <! DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>登录页面</title> <script type="text/javascript"> function RegisterSubmit(){ with(document.Register){ var loginname= username.value; var loginpasswd= passwd.value; if(loginname==null|| loginname==""){ alert("请填写用户名"); }else if(loginpasswd==null|| loginpasswd==""){ alert("请填写密码"); }else { document.Register.submit(); } } } </script> </head> <body> <from action="servlet/LofinServlet" name="Register" method="post"> <center> <table width="600" borfer="0" bacolor="#8FBC8F"> <tr> <td align="right">用户名:</td> <td align="left"><input type="text" name="username" style="widty:120px"/></td> </tr> <tr> <td align="right">密 码:</td> <td align="left"><input type="password" name="passwd" style="widty:120px"/></td> </tr> <tr> <td align="right"><input type="button" value="提交" onClisk="RegisterSubmit()"> </td> <td align="left"><input type="reset" value="重置" /></td> </tr> </table> </center> </body> </html> web.xml文件: <servlet> <servlet-name>LoginServlet</servlet-name> <servlet-class>com.servlet.session.Demo2.LoginServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>LoginServlet</servlet-name> <url-pattern>/servlet/LoginServlet</url-pattern> </servlet-mapping> 问题:启动tomcat后,在网页中键入http://localhost:8080时,正常。但是再键入http://localhost:8080/ServlerDemo/servlet/LoginServlet 时, 怎么出现404错误。是不是我的地址输入错误,正确的地址是哪样的。
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询