• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

root context need help

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I need help

In tomcat they have "jsp-examples" and "servlet-examples" under webapps
I have tried one example of servlet from HFSJ and it worked as I got existed root context means under "jsp-examples".

same thing again I made my project folder under "jsp-examples" and wrote my own web.xml and just wrote <servlet> tag
and tried to do the same thing like which I tried before...this time it didn't work

so I would like to know...

if "jsp-examples" has its own WEB-INF and if I write my own "Myproject/WEB-INF" under "jsp-examples/" will it work?

or

If I want to have my root context under "webapps" what is basic thing to do first.


Thanks
~Vaishoo
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to create "Myproject/WEB-INF" under the webapps directory. Place your web.xml file in the WEB-INF folder.
 
vaishoo Dhembre
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for showing some interest

yes i wrote web.xml under WEB-INF

now i have Mypro/form.html
and Mypro/WEB-INF/classes/****.class file

mapping for servlet is also checked...

in short formally done everything which required..

but dont understand why Mypro under webapp cant work the expected way.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you have :
webapps/Mypro/form.html
webapps/Mypro/WEB-INF/classes/****.class files
webapps/Mypro/WEB-INF/web.xml

Please tell us what is not working the expected way. Post the error, your web.xml, and the url you are trying to access.
 
vaishoo Dhembre
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
case 1)--------------------------------------------

1) C:\tomcat\Tomcat 5.5\webapps\BeerV1\form1.html
<html>
<body>
<form method="GET" action = "/BeerV1/Select.do">
color:
<select name="color" size="1" >
<option>light
<option>amber
<option>brown
<option>red
</select>
<input type="SUBMIT">
</form>
</body>
</html>

2)C:\tomcat\Tomcat 5.5\webapps\BeerV1\WEB-INF\web.xml
<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>SelectBeer</servlet-name>
<servlet-class>example1.SelectBeer</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>SelectBeer</servlet-name>
<uri-pattern>/BeerV1/Select.do</uri-pattern>
</servlet-mapping>

</web-app>

3) C:\tomcat\Tomcat 5.5\webapps\BeerV1\WEB-INF\classes\example1\SelectBeer.class

package example1;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class SelectBeer extends HttpServlet
{
public void doGet(HttpServletRequest req , HttpServletResponse res) throws
IOException,ServletException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("hi vaishoo");

}
}

Error: 404
-------------------------------------------------------------------------------------------------

case 2)
------------------------------------------------------------------------------
Now if i try same example under jsp-examples it is working

1)C:\tomcat\Tomcat 5.5\webapps\jsp-examples\form2.html
2)C:\tomcat\Tomcat 5.5\webapps\jsp-examples\WEB-INF\web.xml
<servlet>
<servlet-name>SelectBeer</servlet-name>
<servlet-class>example1.SelectBeer</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SelectBeer</servlet-name>
<url-pattern>/servlet/SelectBeer</url-pattern>
</servlet-mapping>


3)C:\tomcat\Tomcat 5.5\webapps\jsp-examples\WEB-INF\classes\example1\SelectBeer.class

No error
-----------------------------------------------------------------------------------------------------------------

so my question is
is there anything missing in my own web.xml as i mention in case 1
or any mistake in mapping that servlet?
or any other reason?
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mistake seems to be

<servlet-mapping>
<servlet-name>SelectBeer</servlet-name>
<uri-pattern>/BeerV1/Select.do</uri-pattern>
</servlet-mapping>

Need to write url-pattern, which is correctly written in the second case.

Also this caught my eye
HTML-
<form method="GET" action = "/BeerV1/Select.do">
change to
<form method="GET" action = "Select.do"> - as the context would be added by the web container.

XML
<uri-pattern>/BeerV1/Select.do</uri-pattern>
change to
<url-pattern>/Select.do</url-pattern>

Hope this helps
 
swarna dasa
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An add-on
HTML-
<form method="GET" action = "/BeerV1/Select.do">
could be BeerV1/Select.do as it is just a URL pattern (as long as web.xml also uses the same URL PATTERN)
<form method="GET" action = "BeerV1/Select.do"> - Remove "/" forward slash

which would make the web.xml

<uri-pattern>/BeerV1/Select.do</uri-pattern>
change to
<url-pattern>/BeerV1/Select.do</url-pattern>

However, if your servlet forwards the result to a JSP, then the JSP would need to be under an additional BeerV1 folder

So directory structure would be:-
C:\tomcat\Tomcat 5.5\webapps\BeerV1\form1.html
C:\tomcat\Tomcat 5.5\webapps\BeerV1\WEB-INF\web.xml
C:\tomcat\Tomcat 5.5\webapps\BeerV1\WEB-INF\classes\example1\SelectBeer.class
C:\tomcat\Tomcat 5.5\webapps\BeerV1\BeerV1\<JSP Page>
 
vaishoo Dhembre
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

sorry guys i forgot to mention that
Error :404 in coming for case 1) form1.html itself and servlet-mapping comes later

here it is

i have
webapps----------->jsp-examples
| |
| |-------------->servlet-examples
|
|------->BeerV1


"/jsp-examples" comes with tomcat by default so no problem in executing
even if i write servlet/jsp under "/jsp-examples" and modify web.xml which is already there is fine...goes wel

same with "servlet.examples"

now i have my own

"BeerV1" which is peer to "jsp-examples" and "servlet-examples" as you can see in diagram

under which i have
1)/BeerV1/form1.html
2)/BeerV1/WEB-INF/web.xml
3)/BeerV1/WEB-INF/classes/SelectBeer.class

Error:404 for 1)/BeerV1/form1.html itself

so my guess is tomcat might not be getting resources under /BeerV1
how can we solve this any suggestion? also i will make sure servlet-mapping should not go wrong.
Any Help ???

Thanks
~vaishoo
 
swarna dasa
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried after correcting your html file and web.xml?

When there is a problem with web.xml then your BeerV1 web application is not loaded, hence you get a 404 error on trying to access the form1.html.

Also, it is a good idea to run tomcat from command prompt using startup.bat/ startup.sh... you will see any exceptions due to web.xml on the command prompt.

Change your files and restart tomcat, you should be fine
 
The world's cheapest jedi mind trick: "Aw c'mon, why not read this tiny ad?"
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic