帮助在现有 jsf 项目中创建 servlet
我正在尝试在 JSF 项目中创建一个 servlet。这是我创建的第一个 servlet,我正在使用 http: //www.servletworld.com/servlet-tutorials/simple-servlet-example.html 作为入门示例。
唯一的问题是由于现有的 jsf,我的文件夹结构有点不同。
我可以显示 form.html 页面,但是当我输入我的名字并单击提交时,我收到 404。
我的文件夹结构如下(仅显示相关文件)
catalog (my project in eclipse)
- src
- a
- b
- c
- catalog
- backing
- WelcomeServlet.java
- WebContent
- catalog
- form.html
- WEB-INF
- web.xml
- classes
- a
- b
- c
- catalog
- backing
- WelcomeServlet.class
这是 web.xml 中的 servlet 映射
<servlet>
<servlet-name>WelcomeServlet</servlet-name>
<servlet-class>a.b.c.catalog.backing.WelcomeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>WelcomeServlet</servlet-name>
<url-pattern>/WelcomeServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/form.html </welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
<welcome-file>/index.html</welcome-file>
</welcome-file-list>
这个 url很好地打开了 form.html 页面 http://localhost:8080/catalog/catalog/form。 html
当您单击提交按钮时,它会显示 url http://localhost:8080/ Catalog/catalog/WelcomeServlet 并给出 404 错误。我认为我的 web.xml 文件存在问题,但我不确定,也无法弄清楚这一点。
谢谢
I'm trying to create a servlet inside a JSF project. This is the first servlet that I've created and I'm using http://www.servletworld.com/servlet-tutorials/simple-servlet-example.html as an example to get me started.
The only thing is my folder structure is a little different because of the existing jsf.
I can get the form.html page to display, but when I type my name in and click submit, I get a 404.
My folder structure is as follows (only relevant files shown)
catalog (my project in eclipse)
- src
- a
- b
- c
- catalog
- backing
- WelcomeServlet.java
- WebContent
- catalog
- form.html
- WEB-INF
- web.xml
- classes
- a
- b
- c
- catalog
- backing
- WelcomeServlet.class
Here is the servlet mappings in web.xml
<servlet>
<servlet-name>WelcomeServlet</servlet-name>
<servlet-class>a.b.c.catalog.backing.WelcomeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>WelcomeServlet</servlet-name>
<url-pattern>/WelcomeServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/form.html </welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
<welcome-file>/index.html</welcome-file>
</welcome-file-list>
This url brings up the form.html page just fine http://localhost:8080/catalog/catalog/form.html
When you click the submit button, it brings up the url http://localhost:8080/catalog/catalog/WelcomeServlet and it gives a 404 error. I'm thinking that there is an issue in my web.xml file, but i'm not certain and I can't figure this out.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在第一个 servlet 映射之后添加以下内容:
Try adding this after the first servlet mapping:
据我所知,您的 servlet 映射到 contextroot/WelcomeServlet,并且您正在导航到 contextroot/catalog/WelcomeServlet。它们不是同一件事。
我猜你忘记了 html 中的斜线。
From what I see, your servlet is mapped to contextroot/WelcomeServlet, and you're navigating to contextroot/catalog/WelcomeServlet. They're not the same thing.
I'm guessing you forgot a slash in your html.