aspose file tools*
The moose likes Servlets and the fly likes where to put the servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "where to put the servlets" Watch "where to put the servlets" New topic
Author

where to put the servlets

aaaa aaaa
Greenhorn

Joined: Dec 29, 2002
Posts: 6
hi!

i have created a new dir. c:\Servlets
and have placed the class files there
now how do i access the servlet in the browser i.e.what URL to type in in the browser

madhur
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1121

Hi Madhur,
The URL to use depends on how you have configured your Web Server/Servlet Engine -- which you failed to mention (or if you did, then I missed it -- sorry).
I'll assume that you are using Tomcat as your servlet engine -- since it is the most popular (I believe) and is also the reference implementation for the servlet specification (from SUN Microsystems).
If that is the case, then I'll have to disappoint you again -- because I don't use Tomcat.
With the servlet engine that I use, there is a configuration file where you map the URL's to actual directories, so using your example, I'd have to map "C:\Servlets" to some URL and then I'd use that URL to access my servlet.
I don't know how much you know about servlets (or where you got your knowledge from), but I learned about servlets from the book "Java Servlet Programming" by Jason Hunter (with William Crawford) and I highly recommend it. The book's companion web site is:
http://www.servlets.com
And you can read the book online at the "Safari" online library:
http://safari.informit.com
They are offering a free, two-week trial subscription.
Hope this has helped you.
Good Luck,
Avi.
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

"aaaa aaaa"-
Welcome to the JavaRanch! Please adjust your displayed name to match the JavaRanch Naming Policy.
You can change it here.
Thanks! and again welcome to the JavaRanch!


- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Arun Prasad Namasivayam
Greenhorn

Joined: Jan 02, 2003
Posts: 5
hi,
if u r using tomcat then follow the steps
1. open server.xml in the conf dir
2. create new context path tag for mapping
<Context path="/path/tobe/given/inurl"
docBase="/path/where/servlets/are/placed"
crossContext="false"
debug="0"
reloadable="true" >
</Context>
3.And then in ur case create "Web-inf" dir inside "C:\servlets"
4.then create "classes" dir inside "web-inf"
5.compile all the java servlets and put the class files inside the classes dir
6.then start the tomcat server from the classes dir
7.check in the url
Ex: http://<hostname>:<port>/<path>/<filename>
thanx
arun
Marty Hall
Author
Ranch Hand

Joined: Jan 02, 2003
Posts: 111

i have created a new dir. c:\Servlets
and have placed the class files there
now how do i access the servlet in the browser i.e.what URL to type in in the browser

Well, as the previous reply said, some details are server-dependent. However, there are some general principles that apply to all servers:
  • You almost certainly want to develop and compile in one directory, then deploy the .class files to another directory for testing with your server.

  • I recommend that you do not try to register your development directory as a Web application directory on the server.
  • Since you said you created a C:\Servlets directory, for development, your source code should go in C:\Servlets\directoryMatchingPackageName\. For instance, if your servlet is in package "foo", it should go in C:\Servlets\foo\YourServlet.java
  • For deployment, your .class files should go in

  • something\WEB-INF\classes\directoryMatchingPackage
    What the "something" is is server-dependent, but most servers have a directory for Web applications, so it is usually servers-web-app-dir\your-web-app-name\. With Tomcat, it is tomcat_install_dir\webapps\your-web-app-name. You can also use the server's default Web application (install_dir\webapps\ROOT with Tomcat). JRun, Resin, and ServletExec have default Web apps too.
  • Most servers have an "invoker" servlet that lets you run the servlet without bothering with servlet-mapping entries in web.xml (Tomcat, JRun, ServletExec, and Resin do, at least). So, your URL would be http://hostname/web-app-name/servlet/packageName.ServletName(Use "localhost" for the hostname if running on your desktop). If you use the server's default Web app instead of a custom one, you would use

  • http://hostname/servlet/packageName.ServletName

    For specific examples of all this with Tomcat, please see http://www.moreservlets.com/Using-Tomcat-4.html
    Cheers-
    - Marty


    Java training and consulting<br /><a href="http://www.coreservlets.com/" target="_blank" rel="nofollow">http://www.coreservlets.com/</a>
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: where to put the servlets
     
    Similar Threads
    Displaying thumb nail image
    Back Button detection with Servlet
    Server can't find my servlets
    Gzipping Servlet Response w/ Struts
    sendRedirect fails to post data along with url if the data is too large