Reputation: 17
I am creating a simple servlet on spring tool set / eclips but am failing to run it. on running
the project, i am able to see my index home page html and click on the link for my jsp but fail
to get to the servlet link. i have attached the web.xml file which has the paths. i am
confused
1. what should i put in servlet-name
2. what should i put in servlet-class
3. what should i put in url-patter
4. Is there is any relation between the index.html file and web.xml file.
5. Finally what is my servlet-class supposed to hold?
My index.html holds: ====================
<ul>
<li>To a <a href="HellBoy.jsp">JSP page</a>.
<li>To a <a href="/HellBoy">HelloWorldServlet</a>.
</ul>
My web.xml holds: =================
<servlet>
<servlet-name>HellBoyServlet</servlet-name>
<servlet-class>com.ravi.servlet.HellBoy</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HellBoServlet</servlet-name>
<url-pattern>/Hell</url-pattern>
</servlet-mapping>
-----------------------------------------
The servlet itself is in src/com.ravi.servlet/ directory and called HellBoy.java
On running, i see my index page but i can only successfully click on
href="HellBoy.jsp"
The link to servlet, href="/HellBoy" ---- F A I L S --- giving error -- HTTP Status 404 -
/HellBoy/Hell
Sorry for a silly question but i have been scouring the web for a solution for the whole week :(
Upvotes: 0
Views: 768
Reputation: 12983
/HellBoy
in href
attribute.<url-pattern>
, in this case it it Hell
.web.xml
.Change to
<li>To a <a href="Hell">HelloWorldServlet</a>
what should i put in servlet-name
<servlet-name>
must match both in <servlet>
and <servlet-mapping>
.
what should i put in servlet-class
Fully qualified name of servlet
what should i put in url-patter
URL pattern that you wish.
For all questions, please read carefully The Java EE 6 Tutorial Chapter 15 Java Servlet Technology
Upvotes: 0
Reputation: 2647
You will have to make entry in web.xml like this
<servlet>
<description> desc</description>
<display-name>HelloBoy</display-name>
<servlet-name>HelloBoy</servlet-name>
<servlet-class>com.abc.xyz.HelloBoy</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloBoy</servlet-name>
<url-pattern>/HelloBoy</url-pattern>
</servlet-mapping>
and if you use eclipse for your IDE then directly create new servlet, it will automatically make all entry in web.xml
Upvotes: 1
Reputation: 542
The URL of the servlet should be http://{host}/{appname}/Hell.
if you want to link your servlet access from /HellBoy http://{host}/{appname}/HellBoy, you should
<servlet-mapping>
<servlet-name>HellBoServlet</servlet-name>
<url-pattern>/HellBoy</url-pattern>
</servlet-mapping>
Upvotes: 0