日期:2014-05-17  浏览次数:20689 次

servlet在form的action中的路径设置(jsp+javabean+servlet)
本人是新手来的。。刚学JSP
情况是这样的,我想把表单的内容传给servlet,每次提交的时候都404错误,以下是错误信息

HTTP Status 404 - /UserLogin

--------------------------------------------

type Status report

message /UserLogin

description The requested resource (/UserLogin) is not available.
------------------------------------------------

我是这样写的 <form action ="/UserLogin" method="post">
------------------------------------------------------
web.xml部署
<display-name>UserLogin</display-name>
<servlet-name>UserLogin</servlet-name>
<servlet-class>jsp_servlet_javabean.UserLogin</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UserLogin</servlet-name>
<url-pattern>/UserLogin</url-pattern>
</servlet-mapping>
-----------------------------------------------------
提交前地址:
http://localhost:8080/test/JSP_Servlet_JavaBean/login.jsp
提交后地址:
http://localhost:8080/UserLogin




这帖子我第3次发了,每次解决后又发现有新的问题- -!
上次有个大神帮我解决了上面的问题
-------------------------------------------------
把Web应用的ContextPath给漏了,提交后的路径应该是:http://localhost:8080/test/UserLogin

<form action ="UserLogin" method="post">

修改为

<form action ="/test/UserLogin" method="post">

或者用 <%=request.getContextPath()%> 自动获取 Web应用的contextpath
------------------------------------------------


确实,按照他说的做,在eclipse上运行,问题解决了。
但后来发现在浏览器上运行,遇到了同样的问题
------------------------------------------------
type Status report

message /test/UserLogin

description The requested resource (/test/UserLogin) is not available.
-----------------------------------------------

现在问题是,可以在eclipse上运行,但浏览器上运行出错,难道是要把XML配置到浏览器上???


------解决方案--------------------
重新安装了一次eclipse然后配置了一次tomcat,问题就解决了,现在可以用同一个tomcat在eclipse中运行网站和在IE浏览器上运行网站