Java Servlet URL Mapping

后端 未结 3 988
攒了一身酷
攒了一身酷 2021-01-26 04:56

i fairly new to java servlet.

Please forgive me if this question seems stupid.

I have add servlet mapping such as servlet class and url pattern using netbeans i

相关标签:
3条回答
  • 2021-01-26 05:00

    you need to define welcome file list. see http://download.oracle.com/javaee/1.4/tutorial/doc/WebApp4.html

    http://wiki.apache.org/tomcat/HowTo#How_do_I_override_the_default_home_page_loaded_by_Tomcat.3F

    0 讨论(0)
  • 2021-01-26 05:20

    I see a Facelets page and I see a JSF specific <context-param>, but I don't see the JSF FacesServlet being definied in web.xml, yet you're fiddling with other servlets.

    Aren't you mixing the basic concepts/technologies? Admittedly, the JSP tutorial is missing in Java EE 6 tutorial, but to work with plain vanilla servlets, you'd usually use plain HTML or JSP instead of Facelets.

    Anyway, to invoke a servlet by URL, you need to ensure that the URL matches the <url-pattern> of the servlet as is been definied in the web.xml. You've definied your GreetingDukeServlet to listen on URLs matching /GreetingDukeServlet. So the URL has to be http://localhost:8080/HelloDuke2/GreetingDukeServlet instead.

    If you actually want the URL to be http://localhost:8080/HelloDuke2/greeting instead, then you should change the <url-pattern> to /greeting instead.

    See also:

    • Servlets info page - Contains a little hello world
    0 讨论(0)
  • 2021-01-26 05:22

    Yes, you need define index page for your web app and you can make redirect inside f.e. create page index.html with this contect

    <html><head><meta http-equiv="REFRESH" content="0; url=greeting/"></head></html>
    

    and then in web.xml

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
    
    0 讨论(0)
提交回复
热议问题