• 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

Path Not Reaching Servlet

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic