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

configure a servlet in tomcat

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here Im trying to configure a servlet in Tomcat.But Im just able to see the directory jap1 but not the WEB_INF directory .this is the procedure Im following .Can anyone help me pls.Im new to Tomcat
2.3.1. Preparing Directories
Assume that we want to install the application in a directory named C:\jap1\
In C:\jap1\ create a directory named WEB-INF
In WEB-INF create a directory named classes
In classes create a directory named pack1
By now we have the following path: C:\jap1\WEB-INF\classes\pack1\
Copy C1.class into pack1 directory.
2.3.2. Modifying server.xml
Using a text editor, open the file TH\conf\server.xml
Find the </ContextManager> tag. (Note: this is an end tag)
Directly in the line before it, insert the following:
<Context path="/jap1"
docBase="c:/jap1"
crossContext="false"
debug="0"
reloadable="true" >
</Context>
Save and close the file.
This tells the server to map requests that start with /jap1 (after the server name and port number) to the directory c:/jap1
2.3.3. Modifying web.xml
Using a text editor, create the file: C:\jap1\WEB-INF\web.xml
Copy the following text into the file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<servlet>
<servlet-name> localAlias </servlet-name>
<servlet-class> pack1.C1 </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> localAlias </servlet-name>
<url-pattern> /MyServet </url-pattern>
</servlet-mapping>
</web-app>
Save and close the file.
 
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
I'm not clear on what you mean by this:

Im just able to see the directory jap1 but not the WEB_INF directory


Severs are not allowed to serve anything from WEB-INF
What URL are you trying to use?
Can you get Tomcat to serve plain html files from c:\jap1\
Bill
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by nitin kumar:
Here Im trying to configure a servlet in Tomcat.But Im just able to see the directory jap1 but not the WEB_INF directory .this is the procedure Im following .Can anyone help me pls.Im new to Tomcat


I have the exact same problem!


2.3.2. Modifying server.xml
Using a text editor, open the file TH\conf\server.xml
Find the </ContextManager> tag. (Note: this is an end tag)
Directly in the line before it, insert the following:
<Context path="/jap1"
docBase="c:/jap1"
crossContext="false"
debug="0"
reloadable="true" >
</Context>
Save and close the file.
This tells the server to map requests that start with /jap1 (after the server name and port number) to the directory c:/jap1


I am using Tomcat 4.1.24 and there is no <ContextManager> tag in %CATALINA_HOME%\conf\server.xml. I have added <Context> within <Host> tag and set the attributes like you do. I get a requested resource not available error message when trying to run a servlet.
Yes, I have uncommented the invoker thingie in $CATALINA_HOME/conf/web.xml.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vasanth Rakasi:

Yes, I have uncommented the invoker thingie in $CATALINA_HOME/conf/web.xml.


Sorry, I meant %CATALINA_HOME%\conf\web.xml
 
nitin kumar
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ,
Im able to run my servlet , from directory jap1.Yeah its true that WEB-INF is not to be shown. Now I have some other problem.Now Im trying to connect to a database postgres from the servlet.Then I placed my pgjdbc2.jar in TH\common\lib directory.But I want to connect to database by placing it in C:\jap1.
My web.xml is in
c:\jap1\WEB-INF\web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app>
<resource-ref> <description> Resource reference to a factoryfor java.sql.Connection instances that may be used for talking to a particulardatabase that is configured in the server.xml file. </description>
<res-ref-name>jdbc/myDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<servlet>
<servlet-name> localAlias </servlet-name>
<servlet-class> pack1.Hello </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> localAlias </servlet-name>
<url-pattern> /MyServlet </url-pattern>
</servlet-mapping>
</web-app>
this is ok .
I made the following changes in server.xml of config directory of tomcat
Now here what should be my context and doc base .Actually what are they meant for?.Can there be same context value for both my database resource and my servlet .How if my servlet want to acess 2 databases .Please I want some help
<Context path="/jap1" docBase="c:/jap1" crossContext="false" debug="0" reloadable="true" >
</Context>
<Resource name="jdbc/myDB" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/myDB"> <parameter>
<name>factory</name> <value>org.objectweb.jndi.DataSourceFactory</value>
</parameter>
<!-- configured by default for PostgreSQL, just change the values to set it for your database -->
<parameter>
<name>username</name>
<value>admin</value>
</parameter>
<parameter>
<name>password</name>
<value>admin</value>
</parameter>
<parameter><name>driverClassName</name>
<value>org.postgresql.Driver</value></parameter>
<parameter><name>url</name>
<value>jdbc ostgresql://localhost/javatest</value></parameter>;
</ResourceParams>
 
William Brogden
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
ContextManager was used in Tomcat 3 - there are lots of changes on going to Tomcat 4.
Have you read the "App Developer Guide" in the on-line documentation? It goes into a lot of detail on deploying applications, directory structure, etc.
Bill
 
I have a knack for fixing things like this ... um ... sorry ... here is a consilitory tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic