Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet web.xml url- pattern

 
sahana mithra
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried a servlet program which simply displays helloworld! In the web.xml file I tried many url-patterns but only if i give /* it works. How should i specify the url-pattern?
url-patterns i tired are
http://localhost:8080/helloworld
/helloworld
/helloworld/HelloWorldServlet
[Directory structure : webapps----helloworld-----WEB-INF-------classes----HelloWorldServlet.class
|-----lib-----servlet-api.jar
|-----web.xml]
Please help me.
 
Swastik Dey
Rancher
Posts: 1687
7
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try /helloworld?
 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are missing WEB-INF folder inside your application.. all your class files, libraries and web.xml should be inside WEB-INF..
 
Trivikram Kamat
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sahana mithra wrote:
[Directory structure : webapps----helloworld-----classes-----HelloWorldServlet.class


classes folder should be under webapps/helloworld/WEB-INF/ and not webapps/helloworld/
Just try it, and see if you can get desired output.
 
sahana mithra
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its inside web-inf only. I missed to depict correct directory structure. Now i have corrected it. I tried /helloworld too but still its not working
 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you show us your web.xml and tell us the url you used to access the servlet..
 
mahesh shastri
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sahana,
Can you post your web.xml . so that would be able to tell you exactly what you are missing.
 
rangi vikas
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah kamat is right and in web.xml under <url-pattern> tag "/" represents the application context path which would be "helloworld" in this case.
 
Trivikram Kamat
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the exact error you're getting?
Is it HTTP Status 404 - The requested resource is not available?
 
sahana mithra
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>HelloWorldServlet</servlet-name>
<servlet-class>HelloWorldServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/???</url-pattern>-------------> works only if i give /*

</servlet-mapping>

</web-app>



error:
404 error requested resource not be foucd
/helloworld not found if i give helloworld there
 
Trivikram Kamat
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sahana mithra wrote:
its inside web-inf only


It should be WEB-INF (CAPITAL) and not web-inf
 
Trivikram Kamat
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd faced similar problem in the past.
I just added HelloWorldServlet java file under a package which solved it.

But that shouldn't matter, one should be able to use class which is directly under classes folder and not in any package.
 
mahesh shastri
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
your web.xml is correct . Just put whatever you want to in the place of ??? . After that while accessing this servlet
your URL should be http://localhost:8080/helloworld/???. (??? represents whatever you want to put there . This time
it will work definitely.
Regards
 
sahana mithra
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi mahesh,
Thanks a lot it works fine now
 
sahana mithra
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everyone,
Thank you very much for spending your time in clarifying my doubt. Need your support more
 
Come have lunch with me Arthur. Adventure will follow. This tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!