• 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

Servlet Context Virtual Sandbox

 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I built a web application which has the following structure:
Assignment\
index.jsp
add.jsp
images\
logo.gif
Student\
record.jsp
WEB-INF\
web.xml
classes\
assignment\StudentServlet.class
lib\
dbLibrary.jar
I packaged it as Assignment.war and it was put under C:/tomcat4/webapps/,
i.e. C:/tomcat4/webapps/Assignment.war
I did not set the server.xml for the Context path as it is only a war file.
When I type:
http://localhost:8080/Assignment/index.jsp, it will display properly.
There are 3 links to
1. add.jsp and
2. /Student/record.jsp and
3. assignment.StudentServlet
in the index.jsp page.
When I click the links to add and record jsp pages and the StudentServlet, it said no such files.
I saw the URL are
1. http://localhost:8080/add.jsp
2. http://localhost:8080/Student/record.jsp
3. http://localhost:8080/servlet/StudentServlet
instead of
1. http://localhost:8080/Assignment/add.jsp
2. http://localhost:8080/Assignment/Student/record.jsp
3. http://localhost:8080/Assignment/servlet/StudentServlet
Here is the web.xml:
<servlet>
<servlet-name>StudentServlet</servlet-name>
<servlet-class>assignment.StudentServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>StudentServlet</servlet-name>
<url-pattern>/StudentServlet</url-pattern>
</servlet-mapping>
I think the web.xml has problem. It has not mapped to correct context "Assignment".
How should I set it in web.xml?
I use tomcat 4 and JBuilder 6.
Thanks
 
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Andrew,
why don't you always link from root?
/Assignment/add.jsp
/Assignment/Student/record.jsp
etc.
 
Andrew Parker
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Sorry, I am a newbie and I do the project under JBuilder.
In the JBuilder, here is the structure:
package assignment;
public class StudentServlet {}
Root directory
index.jsp
add.jsp
/Student/record.jsp
The 3 resources in my index.jsp are:
1. /add.jsp
2. /Student/record.jsp
3. /servlet/StudentServlet
The Jbuilder packaged them as an Assignment.war file.
When I typed http://localhost:8080/Assignment, it displayed http://localhost:8080/Assignment/index.jsp.
Why not http://localhost:8080/index.jsp?
If it is http://localhost:8080/Assignment/index.jsp, why not the context "Assignment" cannot be located as follows?
1. http://localhost:8080/Assignment/add.jsp
2. http://localhost:8080/Assignment/Student/record.jsp
3. http://localhost:8080/Assignment/servlet/StudentServlet
If I use another war file name such as assign.war, but the resources links are
1. /Assignment/add.jsp
2. /Assignment/Student/record.jsp
3. /Assignment/servlet/StudentServlet
When I typed http://localhost:8080/assign, it cannot find http://localhost:8080/Assignment/index.jsp.
So, how can I solve it?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you put your code and directory structure maps between UBB CODE tags, the formatting will be preserved. Without them, your directory structure maps are useless, and code is hard to read.
hth,
bear
 
reply
    Bookmark Topic Watch Topic
  • New Topic