aspose file tools*
The moose likes Servlets and the fly likes Servlet web.xml url- pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet web.xml url- pattern" Watch "Servlet web.xml url- pattern" New topic
Author

Servlet web.xml url- pattern

sahana mithra
Ranch Hand

Joined: Oct 26, 2010
Posts: 72
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

Joined: Jan 08, 2009
Posts: 1477
    
    6

Did you try /helloworld?


Swastik
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 537

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

Joined: Sep 26, 2010
Posts: 155
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.


OCPJP6
sahana mithra
Ranch Hand

Joined: Oct 26, 2010
Posts: 72
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

Joined: Apr 25, 2010
Posts: 537

can you show us your web.xml and tell us the url you used to access the servlet..
mahesh shastri
Greenhorn

Joined: Sep 04, 2010
Posts: 11
Hi Sahana,
Can you post your web.xml . so that would be able to tell you exactly what you are missing.
rangi vikas
Greenhorn

Joined: Nov 01, 2010
Posts: 3
yeah kamat is right and in web.xml under <url-pattern> tag "/" represents the application context path which would be "helloworld" in this case.


OCPJP 6.0 (98%)
Trivikram Kamat
Ranch Hand

Joined: Sep 26, 2010
Posts: 155
What's the exact error you're getting?
Is it HTTP Status 404 - The requested resource is not available?
sahana mithra
Ranch Hand

Joined: Oct 26, 2010
Posts: 72
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

Joined: Sep 26, 2010
Posts: 155
sahana mithra wrote:
its inside web-inf only


It should be WEB-INF (CAPITAL) and not web-inf
Trivikram Kamat
Ranch Hand

Joined: Sep 26, 2010
Posts: 155
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

Joined: Sep 04, 2010
Posts: 11
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

Joined: Oct 26, 2010
Posts: 72
hi mahesh,
Thanks a lot it works fine now
sahana mithra
Ranch Hand

Joined: Oct 26, 2010
Posts: 72
hi everyone,
Thank you very much for spending your time in clarifying my doubt. Need your support more
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet web.xml url- pattern