比如Eclipse中的Dynamic Web Project工程A,A的webContent下的一个页面用表单调用servlet.
<form id="form1" method="post" action = "/JSPRequest/firstservlet">
......................................
<input type = "submit" value = "提交">
<input type = "reset" value = "重置">
</form>
A的WEB-INF中的web.xml已经配置:
<web-app>
...............................................
<servlet>
<servlet-name>firstservlet</servlet-name>
<servlet-class>com.demo.servlet.FirstServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>firstservlet</servlet-name>
<url-pattern>/JSPRequest/firstservlet</url-pattern>
</servlet-mapping>
</web-app>
A的src中的com.demo.servlet中有FirstServlet.java
package com.demo.servlet;
.......................
public class FirstServlet extends HttpServlet{
public void services(HttpServletRequest request,
HttpServletResponse response) throws ServletException, java.io.IOException
{
PrintStream out = new PrintStream(response.getOutputStream());
.....................
}
}
接着Run On Server 选择 tomcat 6.0.32
结果显示:
HTTP Status 404 - /JSPRequest/firstservlet
--------------------------------------------------------------------------------
type Status report
message /JSPRequest/firstservlet
description The requested resource (/JSPRequest/firstservlet) is not available.
请问我哪儿配置错了么?还是有什么细节的地方?
------解决方案--------------------------------------------------------
你把<form id="form1" method="post" action = "/JSPRequest/firstservlet">前面的/去掉看看
:
<form id="form1" method="post" action = "JSPRequest/firstservlet">
------解决方案--------------------------------------------------------
- XML code
<servlet> <servlet-name> LoginServlet </servlet-name> <servlet-class> org.cai.servlet.LoginServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>LoginServlet</servlet-name> <url-pattern>/LoginServlet</url-pattern> </servlet-mapping>