wood burning stoves 2.0*
The moose likes Servlets and the fly likes Path Not Reaching Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Path Not Reaching Servlet " Watch "Path Not Reaching Servlet " New topic
Author

Path Not Reaching Servlet

ch praveen
Ranch Hand

Joined: Mar 08, 2004
Posts: 67
Hello Friends,

My project directory structure is as follows:

Tomcat 4.1
|
|
- webapps
|
|
- msgboard [ contains jsp files ]
|
|
- Web-inf [includes web.xml]
|
|
- classes [ contains servlet for eg. HelloWorldExample.class ]


When we invoke the servlet, as
http://localhost:8080/msgboard/servlet/HelloWorldExample, it's returning
The requested resource (/msgboard/servlet/HelloWorldExample) is not available.

web.xml is as follows::

-----------
<web-app>

<display-name>msgboard</display-name>

<description>msgboard</description>

<servlet>
<servlet-name>
HelloWorldExample
</servlet-name>
<servlet-class>
HelloWorldExample
</servlet-class>
</servlet>


</web-app>
-----------

I even tried keeping web.xml under msgboard directory. Plz. help me to get the servlet invoked by the path http://localhost:8080/msgboard/servlet/HelloWorldExample

Regards,
Ch.Praveen Kumar.
ch praveen
Ranch Hand

Joined: Mar 08, 2004
Posts: 67
Hi Friends,

Sorry for inconvenience, in the above post, my project directory
structure is not properly displayed. Iam illustrating this below::

Tomcat 4.1 (top level dir.)

webapps (sub dir. of, Tomcat 4.1)

msgboard [ contains jsp files ] (sub dir. of webapps)

Web-inf [includes web.xml] (sub dir. of msgboard)

classes [ contains servlet for eg. HelloWorldExample.class ] (sub dir. of Web-inf)
Siyaa Hoffman
Greenhorn

Joined: Jan 15, 2004
Posts: 23
Hi Praveen,

I have seen in the recent application servers, I think those having servlet engines for Servlet 2.3 onwards, you cannot invoke the servlet just by placing it in the classes and then using the url .../servlet/...

Try using servlet-mapping in the web.xml and then reload the web application.
ch praveen
Ranch Hand

Joined: Mar 08, 2004
Posts: 67
Hello Siyaa Hoffman,

Thanks for your help. My application is now running. But I got some doubts here.

servlet-mapping tags in web.xml, links the url typed (which referes servlet) to the appropriate servlet. But I want to set security constraints in such a manner that some of the servlets may be directly referred by a user (by typing appropriate url) but others are not accessible. At the same time in my application, any servlet can refer any other servlet without any constraint. Can you include steps that are tobe embedded in web.xml to accomplish a task like this.

Regards,
Ch.Praveen Kumar.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5
the url typed (which referes servlet)

Do NOT use the /servlet/ approach for any serious work. See the JavaRanch FAQ on the Invoker.
Have you read the security documentation that is installed with Tomcat?
Bill
ch praveen
Ranch Hand

Joined: Mar 08, 2004
Posts: 67
Hello Friends,

I have used the approach as stated above. Iam able to access servlets pertainging to my chat application but Iam unable to set security constraints in such a manner that no user can invoke a servlet by directly typing the URL corresponding to the servlet and the same time any servlet must be able to access all other servlets. In my application, I have implemented the below approach. But what happens is the corresponding servlet is not invoked by the login.html page once the user is authorized to enter. Contents of web.xml is listed as follows.

-------------
<?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>HttpChatting</display-name>
<description>
Welcome To HttpChatting
</description>

<!-- Define servlets that are included in the this application -->
<servlet>
<servlet-name>HelloWorldExample</servlet-name>
<servlet-class>HelloWorldExample</servlet-class>
</servlet>

<servlet>
<servlet-name>ChatServlet</servlet-name>
<servlet-class>ChatServlet</servlet-class>
</servlet>

<servlet>
<servlet-name>DisplayContext</servlet-name>
<servlet-class>DisplayContext</servlet-class>
</servlet>

<servlet>
<servlet-name>FileServlet</servlet-name>
<servlet-class>FileServlet</servlet-class>
</servlet>

<servlet>
<servlet-name>LoadApplet</servlet-name>
<servlet-class>LoadApplet</servlet-class>
</servlet>

<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>Login</servlet-class>
</servlet>

<servlet>
<servlet-name>Logout</servlet-name>
<servlet-class>Logout</servlet-class>
</servlet>

<servlet>
<servlet-name>MoniterIdleUsers</servlet-name>
<servlet-class>MoniterIdleUsers</servlet-class>
</servlet>

<!-- Define servlet mappings for servlets that are included in the this application -->
<servlet-mapping>
<servlet-name>HelloWorldExample</servlet-name>
<url-pattern>/HelloWorldExample</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>ChatServlet</servlet-name>
<url-pattern>/ChatServlet</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>DisplayContext</servlet-name>
<url-pattern>/DisplayContext</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>FileServlet</servlet-name>
<url-pattern>/FileServlet</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>LoadApplet</servlet-name>
<url-pattern>/LoadApplet</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/Login</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>Logout</servlet-name>
<url-pattern>/Logout</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>MoniterIdleUsers</servlet-name>
<url-pattern>/MoniterIdleUsers</url-pattern>
</servlet-mapping>

<security-constraint>
<web-resource-collection>
<web-resource-name>
Restricted Area
</web-resource-name>
<url-pattern>/DisplayContext</url-pattern>
<url-pattern>/Login</url-pattern>
</web-resource-collection>
<auth-constraint> </auth-constraint>
</security-constraint>

</web-app>

-----------

Here servet by name 'Login' is not accessible even by login.html (which is not desired) and by user - who directly types path of servlet (which is desired). Kindly suggest me the approach that enables all the html files or servlets in my aplication can refer any other servlet. At the same, users must not be able to invoke the servlet just by typing the path pertaining to the servlet.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Path Not Reaching Servlet