未找到 Servlet 请求的资源
我有 index.jsp
,从中我获取 servlet LoginServlet.java
的参数 servlet 位于 dao 包下。
<form name="LoginForm" method="post" action="dao/LoginServlet">
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Chat</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>LoginServlet</display-name>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>dao.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>Login</url-pattern>
</servlet-mapping>
</web-app>
当我运行 JSP 页面时,我可以看到它,但收到一条错误消息
The requested resource (dao/LoginServlet) is not available
有人能指出问题是什么吗?
I have index.jsp
from which I get the parameters to servlet LoginServlet.java
The servlet is under package dao.
<form name="LoginForm" method="post" action="dao/LoginServlet">
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Chat</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>LoginServlet</display-name>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>dao.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>Login</url-pattern>
</servlet-mapping>
</web-app>
When I run the JSP page I can see it but I get an error telling
The requested resource (dao/LoginServlet) is not available
Can anyone point out wat is the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
表单操作应指向
web.xml
的
条目中指定的 servlet URL代码>.您已声明 servlet 监听Login
,但这实际上是无效的。它应该以斜线开头。这样它就会监听 http://localhost:8080/yourcontextname/Login。
然后您可以让表单操作指向该 URL(假设 JSP 文件没有放置在您的 web 应用程序上下文的子文件夹中)。
另请参阅:
The form action should point to the servlet URL as specified in
<url-pattern>
entry of its<servlet-mapping>
inweb.xml
. You have declared the servlet to listen onLogin
, but this is actually invalid. It should start with a slash.This way it listens on http://localhost:8080/yourcontextname/Login.
Then you can just let the form action point to that URL (assuming that the JSP file isn't placed in a subfolder of your webapp context).
See also: