• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Servlet web.xml url- pattern

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try /helloworld?
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you show us your web.xml and tell us the url you used to access the servlet..
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi everyone,
Thank you very much for spending your time in clarifying my doubt. Need your support more
 
If you are using a wood chipper, you are doing it wrong. Even on this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic