Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Yet another tomcat problem

 
Latha Ganesan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!,
I know there are lot of tomcat related threads in this forum,I solved all my problems till now by reading them. But this time I couldnot find an answer so I am posting a new thread...
I just want to test a simple servlet in tomcat and for that where do I put my .class files? All this while I was using servletrunner and I could directly run a servlet typing the servlet name is the url, can I do the same thing with tomcat or do we need to go through a html only(sorry if i am wrong). If html, where do I put them(which dir). Basically what is the significance of 'Path' and 'docbase' in the server.xml file?
Please help and thanx in advance.
 
Nizan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and I searched and searched until I found the place to put my servlets. TomcatRoot\webapps\examples\WEB-INF\classes. There is a way to change this, but I haven't quite figured it out yet. Maybe one of the ranch hands could open the gate?
 
gayathri reddy
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Latha,
I am using tomcat I don't know about servletrunner.but i place my .classes in tomcat/jakartatomacat/webapps/examples/web-inf/classes folder.
and u can call in the url like this http://localhost:8080/examples/servlet/ur .class file name
hope this help u
-greddy
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know there are lot of tomcat related threads in this forum,I solved all my problems till now
by reading them. But this time I couldnot find an answer so I am posting a new thread...

I really appreciate you doing all the homework!

I just want to test a simple servlet in tomcat and for that where do I put my .class files?
As always there probably are many (confusing) ways of doing it...
One method I follow:

  • Create your project folder under webapps. So now you
    should be having a folder webapps/MyProject. This is known
    as your application root/context etc etc.
  • Under this context, create a folder WEB-INF and under
    which you have to create the folder classes. So you now
    have webapps/MyProject/WEB-INF/classes
  • Put your class files under the folder webapps/MyProject/WEB-INF/classes
  • Your HTML/JSPs go to the root of your application which is
    webapps/MyProject
  • The last thing you need todo is to add a new servlet context.
    Open the conf/server.xml file, copy one of the contexts say the
    examples and change the path and docBase

  • You should be able to access your servlet/JSP etc.

    All
    this while I was using servletrunner and I could directly run a servlet typing the servlet
    name is the url, can I do the same thing with tomcat or do we need to go through a html
    only(sorry if i am wrong). If html, where do I put them(which dir).

    I think you could directly call servlets. See above abt HTML files.
    Basically what is the
    significance of 'Path' and 'docbase' in the server.xml file?
    Please help and thanx in advance.

    Path as I understand is the part of URL which needs to be specified and docBase is the place where your application is
    deployed ie; your WEB-INF dir is under this dir and that this is
    your applications root.
    HTH.
    - satya
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TomcatRoot\webapps\examples\WEB-INF\classes. There is a way to change this, but I
haven't quite figured it out yet. Maybe one of the ranch hands could open the gate?

Nizan:
You are right. There is no way to change this. It is printed in
stone in the Servlet Specs. Hence all application Servers
which implement the Servlet Specs. require this.
and I also should re-direct you to the javaranch names.jsp. Pl.
review this and re-register http://www.javaranch.com/name.jsp
Thanks for your cooperation.
- satya
 
vaibhav punekar
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the only way you can change the structure is to add your application package name under \WEB-INF\classes folder.But that does not mean the change.Only we are separating the class files according to their applications and putting them in the corresponding pakages.So as suggested by Madhav I also always create my webapps folder(like myproject etc).The same name I give
to the package under "classes".
So "tomcatroot\webapps\myproject\WEB-INF\classes\myproject".
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

vaibhav:
just a clarification........IMO,
you are NOT changing the structure, you are just creating a
new context or a new application, which in its own way HAS to
follow the structure.
the way I see it....
- satya
 
Latha Ganesan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all!,
Thanx a lot... yes it did work. Yes, u folks are right, we cannot change the structure, I suppose we can only create packages for our own applications and put it under 'classes' dir and classes in default package should go to the 'classes' dir straight.
Another ques, is tomcat an application server or it can serve only servlets and jsps (like what about ASP?)
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tomcat is an application server in its own way!
It serves applications based on JSP and Servlets.
Yes, it is limited to Servlets and JSP's.
Whats' that ASP you are talking abt
- satya
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think she means Microsoft's ASP (Active Server Pages) technology. If so, no Tomcat doesn't serve ASP pages.
regds
maha anna
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic