• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unable to compile

 
deepa nari
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/** Simple servlet used to test server.
* <P>
* Taken from More Servlets and JavaServer Pages
* from Prentice Hall and Sun Microsystems Press,
* http://www.moreservlets.com/.
* © 2002 Marty Hall; may be freely used or adapted.
*/
public class HelloServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String docType =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
"Transitional//EN\">\n";
out.println(docType +
"<HTML>\n" +
"<HEAD><TITLE>Hello</TITLE></HEAD>\n" +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1>Hello</H1>\n" +
"</BODY></HTML>");
}
}

I have installed above HelloServlet.java in C:\tomcat4.1\webapps\root\web-inf\classes
When i try to compile it i get 6 errors as
import javax.servlet.http.*;
^
HelloServlet.java:13: cannot resolve symbol
symbol : class HttpServlet
location: class HelloServlet
public class HelloServlet extends HttpServlet {
^
HelloServlet.java:14: cannot resolve symbol
symbol : class HttpServletRequest
location: class HelloServlet
public void doGet(HttpServletRequest request,
^
HelloServlet.java:15: cannot resolve symbol
symbol : class HttpServletResponse
location: class HelloServlet
HttpServletResponse response
^
HelloServlet.java:16: cannot resolve symbol
symbol : class ServletException
location: class HelloServlet
throws ServletException, IOException {
^
6 errors
Can anyone try to resolve as why???
 
Maha Annadurai
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Deepa,
1. Open up your autoexec.bat,
2. Add this line to your CLASSPATH,
set classpath=C:\tomcat4.1\common\lib\servlet.jar;C:.;[and all your others classpaths]
3. save it
4. close the current command prompt, openup a new window
5. cd\
6. autoexec.bat
7. set
8. cd C:\tomcat4.1\webapps\root\web-inf\classes
9. javac HelloServlt.java

It should work now. The reason you are unable to compile servlet files is, javac is not able to find the servlet related class files. The servlet.jar does not come with standard java sdk.
Usually the jsp container comes with servlet.jar. So we need to explicitly say where the servlet.jar is in classpath.
I have Tomcat4.0.3 installed in my machine and the servlet.jar is under C:\jakarta-tomcat-4.0.3\common\lib. Please check yours and put the right path.
Regards,
Maha Anna
[ December 04, 2002: Message edited by: Maha Annadurai ]
 
deepa nari
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it.
But when i try to open http://localhost:8080/servlet/HelloServlet
in the browser i get as
HTTP Status 404 - /servlet/HelloServlet
type Status report
message /servlet/HelloServlet
description The requested resource (/servlet/HelloServlet) is not available.
Any help as to why get it???
 
Maha Annadurai
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you start Tomcat?
-Maha
 
deepa nari
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i started tomcat.Tomcat runs fine but in the browser i get error as
HTTP Status 404 - /servlet/HelloServlet
--------------------------------------------------------------------------------
type Status report
message /servlet/HelloServlet
description The requested resource (/servlet/HelloServlet) is not available.

--------------------------------------------------------------------------------
Apache Tomcat/4.1.12
 
Maha Annadurai
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this
http://localhost/servlet/HelloServlet

If you still get the error, copy your HelloServlet.class to C:\Tomcat4.1\webapps\examples\WEB-INF\classes dir and stop and start Tomcat.
Try this way
http://localhost:8080/examples/servlet/HelloServlet
OR
http://localhost/examples/servlet/HelloServlet
-Maha
[ December 04, 2002: Message edited by: Maha Annadurai ]
 
deepa nari
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Giving http://localhost/servlet/HelloServlet
I get as
The page cannot be displayed in the browser.
 
Maha Annadurai
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read my prev. post. and try that way.
What happens when you just type http://localhost/
or http://localhost:8080 ?
Are you seeing the Tomcat welcome page? are you able to run the servlet and jsp examples come with Tomcat?
-Maha
 
deepa nari
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I copied HelloServlet.class to C:\Tomcat4.1\webapps\examples\WEB-INF\classes dir
By giving
http://localhost:8080/examples/servlet/HelloServlet
in the browser worked fine..
But in the documentation its given as to keep java and class files in
c:\Tomcat4.1\webapps\Root\Web-inf\classes
i created classes folder under Web-inf and put my java and class files underneath it.
and started tomcat , that works fine but in the browser i get error as
HTTP404 error
Why is that???
Any clue Maha Anna?
 
deepa nari
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In
http://www.moreservlets.com/Using-Tomcat-4.html#Test1
there is a section called
Test 1: A Servlet That Does Not Use Packages
Test 2: A Servlet That Uses Packages
Test 3: A Servlet That Uses Packages and Utilities
What i did was Test1.
How about the Test2 and Test3
In what way i have to run this???
 
Maha Annadurai
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regarding your ROOT context problem, I suspect the default context is not correctly configured.
Open up your server.xml in C:\Tomcat4.1\conf dir and check for the following section.
Uncomment it, (remove <!-- and --> lines ) save it , restart Jrun and try to access http://localhost:8080/servlet/HelloServlet.
<!--
<Context path="" docBase="ROOT" debug="0"/>
-->
See what happens ?
-Maha
[ December 04, 2002: Message edited by: Maha Annadurai ]
 
deepa nari
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I removed <!-- and --> in
<Context path="" docBase="ROOT" debug="0"/>
from server.xml
Tomcat runs fine but in the browser when i give http://localhost:8080/servlet/HelloServlet
i get the same error as
HTTP Status 404 - /servlet/HelloServlet
--------------------------------------------------------------------------------
type Status report
message /servlet/HelloServlet
description The requested resource (/servlet/HelloServlet) is not available.

--------------------------------------------------------------------------------
Apache Tomcat/4.1.12
 
Maha Annadurai
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did the same thing with my server.xml, restarted Tomcat, and it works fine. Do you have you HelloServlet.class file under C:\Tomcat4.1\webapps\ROOT\WEB-INF\classes dir? Or have you moved to examples ? Just double check on it.
Not sure what's wrong .
Anyway, my suggestion is do not work with default context. Always try to work under a named context like 'examples' or create your own one and play under that.
Regards,
Maha Anna
 
deepa nari
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already moved my HelloServlet.class file under C:\Tomcat4.1\webapps\ROOT\WEB-INF\classes dir?
Not working for me??

did u created classes dir under C:\Tomcat4.1\webapps\ROOT\WEB-INF\Web-inf?
 
Maha Annadurai
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. I did. At first, the 'classes' dir was not there. I manually created it. My HelloServlet is here
C:\jakarta-tomcat-4.0.3\webapps\ROOT\WEB-INF\classes\HelloServlet.class
-Maha
 
deepa nari
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank u Maha Anna.
But don't know why isnt it working for me..
 
Yumei Guo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have experienced one case sensetive problem when I worked with Tomcat in my PC environment.
eg:, I have a directory created, and class file stored as myPro/testServlet, but I keep getting Error from browser, when I changed it to lower case as mypro/testServlet, it worked.
Try to check that and see if that help on your problem.
Hint root\web-inf vs. ROOT\WEB-INF.
have installed above HelloServlet.java in C:\tomcat4.1\webapps\root\web-inf\classes
C:\jakarta-tomcat-4.0.3\webapps\ROOT\WEB-INF\classes\HelloServlet.class
 
deepa nari
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this too didn't work for me
 
John Pritchard
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depa-
Your problem is that you do not have the j2ee.jar in your classpath. This is the .jat that contains all of the J2EE APIs.
You need to add:
set path=%path%c:/j2eesdk1.4/lib/j2ee.jar;
to your autoexec
(This assumes you have downloadede the J2EE SDK and you installed it in c:\j2eesdk1.4)
 
Jayii Young
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try adding
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
in your web.xml between <web-app>
 
deepa nari
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank u very much dawn now it worked....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic