在Eclipse里Servlet的路径问题,求救各位高手啊~~~
我的Web.xml是这样的:
<?xml version= "1.0 " encoding= "UTF-8 "?>
<web-app version= "2.4 "
xmlns= "http://java.sun.com/xml/ns/j2ee "
xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance "
xsi:schemaLocation= "http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
<servlet>
<description> This is the description of my J2EE component </description>
<display-name> This is the display name of my J2EE component </display-name>
<servlet-name> LoginServlet </servlet-name>
<servlet-class> controller.LoginServlet </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> LoginServlet </servlet-name>
<url-pattern> /servlet/LoginServlet </url-pattern>
</servlet-mapping>
</web-app>
我的表单是: <form action= "/servlet/LoginServlet " name= "LoginForm " method= "post ">
我实在是按照url-pattern的值写的地址,但总是提示HTTP Status 404 - /WebRoot/servlet/LoginServlet的错误,请各位老师指导我纠正错误~~
[解决办法]
<form action= "/servlet/LoginServlet "
改为:
<form action= "/servlet/你的包名.LoginServlet "
[解决办法]
改成这个 <form action= " <%=request.getContextPath()%> /servlet/LoginServlet " name= "LoginForm " method= "post ">
试试
[解决办法]
我的表单是: <form action= "/servlet/LoginServlet " name= "LoginForm " method= "post ">
->
<form action= "/servlet/LoginServlet.do " name= "LoginForm " method= "post ">
http://localhost:8080/servlet/LoginServlet.do?
[解决办法]
在映射servlet的时候去掉前面的‘/’在试一下看看先 如下:
<servlet-mapping>
<servlet-name> LoginServlet </servlet-name>
<url-pattern> servlet/LoginServlet </url-pattern>
</servlet-mapping>
然后提交到http://localhost:8080/项目名/servlet/LoginServlet
以上你可以试一下。