Forums Register Login

Doubt in servlet

+Pie Number of slices to send: Send
Hi All,
I m trying to develop a really basic servlet. My application structure goes like this.

test - root
webapps - test - WEB-INF - web.xml
webapps- test - WEB-INF - test.jsp
webapps - test - classes - servlets - TestServlet.class
webapps - test - classes - beans - TestBean.class

Here I cant call my servlet directly from the Address basr using this URL
http://localhost:8080/test/TestMe

What wrong am i doing here??
Pls help.

here is the copy of my web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>

<servlet>
<servlet-name>Test</servlet-name>
<servlet-class>servlets.TestServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>test/Testme</url-pattern>
</servlet-mapping>
</web-app>


Regards,

Preeti
+Pie Number of slices to send: Send
<url-pattern>test/Testme</url-pattern>

change to

<url-pattern>/test/Testme</url-pattern>

and try this...


and one more

webapps- test - WEB-INF - test.jsp
to
webapps- test - test.jsp

place all jsps file under test
+Pie Number of slices to send: Send
 


webapps - test - WEB-INF - web.xml



Correct


webapps- test - WEB-INF - test.jsp



Wrong.(This is correct but can't be accessed directly.) Correct it to
webapps- test - test.jsp.


webapps - test - classes - servlets - TestServlet.class



Wrong. Correct it
webapps - test - WEB-INF - classes - servlets - TestServlet.class


webapps - test - classes - beans - TestBean.class



Wrong. Correct it(put all classes in one package)
webapps - test - WEB-INF - classes - servlets - TestBean.class


Here I cant call my servlet directly from the Address basr using this URL
http://localhost:8080/test/TestMe



Correct the URL to
http://localhost:8080/MyWebApplication/test/TestMe


<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>test/Testme</url-pattern>
</servlet-mapping>



url-pattern element is Wrong. Correct it to

<url-pattern>/test/Testme</url-pattern>

Note: I had a slash in front of test.
[ February 08, 2006: Message edited by: Vishnu Prakash ]
+Pie Number of slices to send: Send
Thanks Vishnu and RaghuNath for ur replies.
First of all aplogies for the little mistake in the file structure i have provided initially

my jsp is actually in 'test' and not WEB-INF .. so its test/test.jsp
and classes are in the WEB-INF directory as separate folders for beans and servlets.

Vishnu - i have tried /test/TestMe . It didnt help.
do i have to give the package name (servlets) since servlet in inside a pkg. Btw i have tried that, i dont think I am using the right URL?

RaghuNath - I wanted to keeps my beans separate from the servlets, thats why I have created two packages inside the classes. I dont think thats wrong?? Your suggestions please.


Regards
+Pie Number of slices to send: Send
Hi preetiarvind -

if you look closely at what Vishnu wrote, you'll see that you need to put your class files inside a directory called classes within WEB-INF. This classes directory is part of the classpath, so what packages you put inside there will be picked up by the servlet container. If you wish to have your own package structure inside this, go ahead.


Vishnu - i have tried /test/TestMe . It didnt help.
do i have to give the package name (servlets) since servlet in inside a pkg. Btw i have tried that, i dont think I am using the right URL?



your url-pattern needs to start with a slash as pointed out. However, it need not reflect your physical package structure - the whole point is that it's declarative, so that you could change the back-end package structure without affecting the front-end.

I Assuming you have tomcat running on port 8080, think you should be able to get to your servlet with http://localhost:8080/test/test/Testme

http://localhost:8080/test

should get you to the root of your webapp... then you specified that you wanted the url /test/Testme to map to the servlet, so...

Hope that helps,
+Pie Number of slices to send: Send
Thanks Daniel,

I ll try that now

Preeti
+Pie Number of slices to send: Send
it worked.
Thank you all for the help


preeti
It's feeding time! Give me the food you were going to give to this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 889 times.
Similar Threads
Deploying the application
running a servlet from a new web application
compiling and deploying into Tomcat
Starting out on Servlets - from Head First Servlets and JSP
help me deploy my webapp
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:22:16.