• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

A Servlet That Uses Packages and Utilities

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a problem for
Test 3: A Servlet That Uses Packages and Utilities
from http://www.moreservlets.com/Using-Tomcat-4.html#Test3
I have HelloServlet3.java and ServletUtilities.java under moreservlets dir
When i try to compile HelloServlet3.java i get the following error but ServletUtilities.java compiles fine..
C:\tomcat4.1\webapps\examples\WEB-INF\classes\moreservlets>javac HelloServlet3.
ava
HelloServlet3.java:23: cannot resolve symbol
symbol : variable ServletUtilities
location: class moreservlets.HelloServlet3
out.println(ServletUtilities.headWithTitle(title) +
^
1 error
Any suggestions??
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to adjust your classpath for the package. Open up you autoexec.bat and add this line at front.
set classpath=C:\Tomcat-4.1\webapps\ROOT\WEB-INF\classes;[and others]
close the current window, open a new command prompt,
cd \
autoexec.bat
set
now go to your dir and try to compile.
-Maha
 
Maha Annadurai
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The instructions are clearly given in that link you posted .
-Maha
 
deepa nari
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did set my class path and others
Look at my classpath in autoexec.bat
set classpath=c:\tomcat4.1\webapps\Root\Web-inf\classes;
SET CATALINA_HOME=c:\tomcat4.1
SET JAVA_HOME=c:\j2sdk1.4.1
SET CLASSPATH=.;C:\ServletDevel;C:\tomcat4.1\common\lib\servlet.jar
SET PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;C:\;C:\DOS;c:/j2sdk1.4.1/bin
but still i get the same error
C:\tomcat4.1\webapps\ROOT\WEB-INF\classes>cd moreservlets
C:\tomcat4.1\webapps\ROOT\WEB-INF\classes\moreservlets>javac HelloServlet3.java
HelloServlet3.java:23: cannot resolve symbol
symbol : variable ServletUtilities
location: class moreservlets.HelloServlet3
out.println(ServletUtilities.headWithTitle(title) +
^
1 error
 
Maha Annadurai
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are not appending to the old classpath. You have classpath set 2 times by 2 separate SET commands. So you are essentially overwriting the first one. You need to have a single entry only.
Remove both separate classpaths settings in autoexec.bat , and have a single line like below.
set classpath=c:\tomcat4.1\webapps\Root\Web-inf\classes;C:.;C:\ServletDevel;C:\tomcat4.1\common\lib\servlet.jar
-Maha
[ December 04, 2002: Message edited by: Maha Annadurai ]
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my question is related to this topic. so i'm posting it here.
How do i access this servlet from my browser
webapps/myapp/WEB-INF/classes/test.class
i have no package declaration in my class.
 
Maha Annadurai
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Either this
http://localhost:8080/myapp/servlet/test
or
http://localhost/myapp/servlet/test
(Actually you can give any port you want if it was condifured correctly in container specific file)
Regards,
Maha Anna
 
Don Bosco
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nope. i'm unable to access it using the URLs u gave.
i have a question. do we have to place all our servlets in the ROOT/WEB_INF/classes?
can't we have our own directory under webapps?
i'm confused
Please somebody explain this concept clearly.
 
Maha Annadurai
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. It is not needed. It is not a must that we should put our class files under ROOT/WEB_INF/classes dir always. A servlet/jsp based web app has a standard dir structure to follow. It is like this
app_context
app_context\all web docs (jsp,html,images)
app_context\WEB-INF\web.ml
app_context\WEB-INF\classes\*.class
app_context\WEB-INF\lib\*.jar
As long as we follow this above structure, we can always create new context like yours (myapp) and access from browser.
Can you try this? Just write a simple jsp and put it under webapps\myapp\test.jsp, and invoke it from browser like this.
http://localhost:8080/myapp/test.jsp
or
http://localhost/myapp/test.jsp
Note that, the url is case sensitive. we have to give the exact name including the exact case of the jsp.
-Maha
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Couple of issues.
If you are using tomcat 4.x, you should have your servlet in a valid package.
compile servlet class, place it in WEB-INF/classes/packagename/ folder.
If you have'nt disabled invoker servlet in web.xml, you should be able to access your servlet by http://localhost/servlet/package.class, provided your tomcat is up and running.
If you are using your tomcat4.x default installation without any changes, place your class under <tomcat-installation-dir>/ROOT/WEB-INF/classes/packagename, then you should be able to access it.
If you are unsure about tomcat running, if running - on which port, use windows command netstat -a
Still unsuccessful, please post stdout.log from tomcat/logs directory
HTH
--
Venkat
To access an unmapped servlet, you don't need to use <yourapp> name in URL, you can access it using generic /servlet/package.class
[ December 04, 2002: Message edited by: sita kodali ]
 
Maha Annadurai
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Tomcat 4.0.3 and able to access a simple class which is NOT in a package without any problem.
Here is a sample url I tested.
http://localhost:8080/examples/servlet/HelloWorldExample
-Maha
 
deepa nari
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Iam ably to compile my HelloServlet3.java file but unable to access http://localhost:8080/servlet/moreservlets.HelloServlet3 from browser..
Thanks for ur prompt replies..
Any help in this Maha..
 
deepa nari
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh got it maha I have to say http://localhost:8080/examples/servlet/moreservlets.HelloServlet3 in the browser..
One question why do i have to use SET CLASSPATH=c:\tomcat4.1\webapps\Root\Web-inf\classes in autoexec.bat
when iam trying to use C:\tomcat4.1\webapps\examples\WEB-INF\classes\moreservlets>
ava
in the browser
 
Don Bosco
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm still not getting it Anna. Do i have to mention something in server.xml about myapp?
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the late replies. Due to Bad weather (snow with ice) we are out of electricity. I am replying this from my work. So you may not expect me to reply soon.
Don Bosco,
No we need not do anything in server.xml when we add a new app.
Are you able to execute the servlet/jsp examples which come with Tomcat's index.html ? You can access them either by http://localhost:8080 or http://localhost . If they work, then just copy the whole examples dir to [Tomcat Installdir]\webapps\[copyOfExamples]
and rename copyOfExamples to "yourApp" or something and put your test.class under classes dir like this.
[TomcatInstallDir]\webapps\yourApp\classes\test.class
and try to access it.
Regards
Maha Anna
[ December 06, 2002: Message edited by: maha anna ]
 
Don Bosco
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With the knowledge of current weather I assume you live somewhere near the carolinas.
Yaa i just came across your suggestion of copying examples directory while searching the google. I will try it after going home.
I also read somewhere that we need to add a context path in server.xml. But u say that we dont have to.
I will try both of them and I will let you know.
Thanks Dude.
 
Don Bosco
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
YEAH Anna. Got it!
But what's the funda in it? This is what I did.
1. I made a copy of the examples directory as u said in webapps. I named it as myapp.
2. I removed all the unnecessary directories and files in myapp. All i got is
myapp->WEB-INF->classes->first->design.class
3. I modified the web.xml and this is what it has got in it
<web-app>
<servlet>
<servlet-name>design</servlet-name>
<servlet-class>first.design</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>design</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

But the point is this is what I had before in my web.xml.
Any inkling what's going on behind? maybe the file permissions of examples directory?
 
Don Bosco
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And forgot to tell you that the modifications in server.xml did not work out. you are right!
 
This is my favorite tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic