tomcat下部署web项目从页面跳转至servlet的404错误,求指点!在线等啊
web.xml:<servlet><servlet-name>login</servlet-name><servlet-class>com.test.servlet.Lo...
web.xml:
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>com.test.servlet.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/loginServlet</url-pattern>
</servlet-mapping>
页面表单部分:
<form id="form1" name="form1" method="post" action="/loginServlet">
<table>
<tr>
<td>用户名:
<label>
<input type="text" name="username" />
</label>
</td>
</tr>
<tr>
<td>密 码:
<input type="password" name="password" />
</td>
</tr>
<tr>
<td><label>
<input type="submit" name="Submit" value="提交" />
<input type="reset" name="Submit2" value="重置" />
</label></td>
</tr>
</table>
</form>
servlet:
public class LoginServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public LoginServlet()
{
}
/**
*
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
this.doPost(request, response);
}
/**
*
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
PrintWriter writer = response.getWriter();
// writer.print("<script>alert('登录成功!');window.location.href='跳到登陆成功后的页面'</script>");
writer.print("<script>alert('登录成功!');</script>");
String username = request.getParameter("username");
String password = request.getParameter("password");
System.out.println(username + "," + password);
request.getRequestDispatcher("/success.jsp").forward(request, response);
// response.sendRedirect("/WebTest/WebContent/jsp/success.jsp");
} 展开
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>com.test.servlet.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/loginServlet</url-pattern>
</servlet-mapping>
页面表单部分:
<form id="form1" name="form1" method="post" action="/loginServlet">
<table>
<tr>
<td>用户名:
<label>
<input type="text" name="username" />
</label>
</td>
</tr>
<tr>
<td>密 码:
<input type="password" name="password" />
</td>
</tr>
<tr>
<td><label>
<input type="submit" name="Submit" value="提交" />
<input type="reset" name="Submit2" value="重置" />
</label></td>
</tr>
</table>
</form>
servlet:
public class LoginServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public LoginServlet()
{
}
/**
*
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
this.doPost(request, response);
}
/**
*
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
PrintWriter writer = response.getWriter();
// writer.print("<script>alert('登录成功!');window.location.href='跳到登陆成功后的页面'</script>");
writer.print("<script>alert('登录成功!');</script>");
String username = request.getParameter("username");
String password = request.getParameter("password");
System.out.println(username + "," + password);
request.getRequestDispatcher("/success.jsp").forward(request, response);
// response.sendRedirect("/WebTest/WebContent/jsp/success.jsp");
} 展开
1个回答
展开全部
<form id="form1" name="form1" method="post" action="/loginServlet">\
<servlet-name>login</servlet-name>
看见这俩个了么?
你提交的是loginServlet,但是你的web.xml中没有这个servlet,
也就是你在配置这个xml文件的过程中出现了错误。
改成login试试!
<servlet-name>login</servlet-name>
看见这俩个了么?
你提交的是loginServlet,但是你的web.xml中没有这个servlet,
也就是你在配置这个xml文件的过程中出现了错误。
改成login试试!
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询