开发者

Help creating servlet in existing jsf project

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 bec开发者_如何学Goause 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


Try adding this after the first servlet mapping:

<servlet-mapping>
    <servlet-name>WelcomeServlet</servlet-name>
    <url-pattern>/catalog/WelcomeServlet</url-pattern>
</servlet-mapping>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜