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??
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
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
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 ]
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.
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
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 ]
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 ]
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.
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>