File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes what's wrong with this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "what Watch "what New topic
Author

what's wrong with this?

krishna akula
Greenhorn

Joined: Mar 29, 2001
Posts: 13
import java.io.*;
import javax.Servlet.*;
import javax.Servlet.http.*;
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("<title>Hello World!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hello World!</h1>");
out.println("</body>");
out.println("</html>");
}
}
what i swrong with my above program?

iam getting the following error:
import javax.Servlet.http;
^
HelloWorld.java:5: cannot resolve symbol
symbol : class HttpServlet
location: class HelloWorld
public class HelloWorld extends HttpServlet {
^
HelloWorld.java:7: cannot resolve symbol
symbol : class HttpServletRequest
location: class HelloWorld
public void doGet(HttpServletRequest request, HttpServletResponse response)
^
HelloWorld.java:7: cannot resolve symbol
symbol : class HttpServletResponse
location: class HelloWorld
public void doGet(HttpServletRequest request, HttpServletResponse response)
^
HelloWorld.java:8: cannot resolve symbol
symbol : class ServletException
location: class HelloWorld
throws IOException, ServletException
^
6 errors
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
import javax.Servlet.*;
import javax.Servlet.http.*;

should be:
import javax.servlet.*;
import javax.servlet.http.*;
see the difference.........
regds.
- saya

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
k b
Greenhorn

Joined: Feb 01, 2001
Posts: 22

Looks like servlet.jar is missing from your class path, if so add c:/whereitis/servlet.jar to the class path and try compiling again.
Hope this helps.
krishna akula
Greenhorn

Joined: Mar 29, 2001
Posts: 13
i made those changes and also included
c:\software\tomcat\lib\servlet.jar
in the classpath.
still the same result iam getting.
krishna akula
Greenhorn

Joined: Mar 29, 2001
Posts: 13
Looks like nobody interested in answering my question.
there is no servlet.jar in my jdk1.3.0_02\lib.
I think i need to have servlet.jar in my jdk1.3.0_02\lib to my servlet work properly.
correct me if i am wrong.
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Krishna,
This is my classpath setting in c:\autoexec.bat file in win98 platform. We can keep the servlet in any dir.But that dir must be in classpath. I have servlet.jar as C:\jakarta-tomcat\lib\servlet.jar.Just make a search in your file system to see if there are 2 versions of servlet.jar which are in classpath.
Did you install jsdk/jswdk also in your machine? Sometimes the servlet.jar which came with old jsdk , give lots of headache when we try to use Tomcat.
If you find any other servlet.jar other than the one came with Tomcat just rename them and see.
regds
maha anna


[This message has been edited by maha anna (edited March 31, 2001).]
krishna akula
Greenhorn

Joined: Mar 29, 2001
Posts: 13
i don't have jsdk in my machine.and also my autoexec has,
C:\PROGRA~1\NETWOR~1\MCAFEE~1\SCAN.EXE C:\
@IF ERRORLEVEL 1 PAUSE
set JAVA_HOME=c:\jdk1.3.0_02
set path=c:\jdk1.3.0_02\bin
set TOMCAT_HOME=c:\software\tomcat
set class_path=c:\jdk1.3.0_02\lib\tools.jar
set class_path=%class_path%;c:\raji
set class_path=%class_path%;c:\software\tomcat\lib\servlet.jar
what is the problem then?
Rahul Rathore
Ranch Hand

Joined: Sep 30, 2000
Posts: 324
Krishna, did you make the changes suggested by Madhav i.e. did you change capital S to small s in the import statements? i.e. did you change Servlet to servlet?
Are the error messages exactly the same? If both the code and error messages have changed then maybe you could post them.
krishna akula
Greenhorn

Joined: Mar 29, 2001
Posts: 13
Here is my code:
--------------------------------------------------------------
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("<title>Hello World!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hello World!</h1>");
out.println("</body>");
out.println("</html>");
}
}
And this is the error message iam getting :
________________________________________________
import javax.servlet.http.*;
^
HelloWorld.java:5: cannot resolve symbol
symbol : class HttpServlet
location: class HelloWorld
public class HelloWorld extends HttpServlet {
^
HelloWorld.java:7: cannot resolve symbol
symbol : class HttpServletRequest
location: class HelloWorld
public void doGet(HttpServletRequest request, HttpServletResponse response)
^
HelloWorld.java:7: cannot resolve symbol
symbol : class HttpServletResponse
location: class HelloWorld
public void doGet(HttpServletRequest request, HttpServletResponse response)
^
HelloWorld.java:8: cannot resolve symbol
symbol : class ServletException
location: class HelloWorld
throws IOException, ServletException
^
6 errors
And this is my autoexec.bat:
___________________-----_________________________________________

C:\PROGRA~1\NETWOR~1\MCAFEE~1\SCAN.EXE C:\
@IF ERRORLEVEL 1 PAUSE
set JAVA_HOME=c:\jdk1.3.0_02
set path=c:\jdk1.3.0_02\bin
set TOMCAT_HOME=c:\software\tomcat
set class_path=c:\jdk1.3.0_02\lib\tools.jar
set class_path=%class_path%;c:\raji
set class_path=%class_path%;c:\software\tomcat\lib\servlet.jar
mahadevan raja
Ranch Hand

Joined: Apr 11, 2001
Posts: 96
hey,
since anna had given u the classpath it might be right,what i doubt is what did u save the file as helloworld.java or Hello
World.java,this might lead to cannot resolve symbol HelloWorld,check it out,else sorry,i have not checked ur classpath since anna had given u the solution.

rm

SPECIALIST-WCSV5.1 Implementation.<br />SYSTEMS EXPERT-WAS4.0 Administration
vaibhav punekar
Ranch Hand

Joined: Jan 20, 2001
Posts: 134
Hi,
I think problem is with the dir structure.There is always "jakatas-tomcat-3.2.1" dir created wherever you install tomcat.So I think it should be
"c:\software\tomcat\jakarta-tomcat-3.2.1\lib\servlet.jar"
instead of c:\software\tomcat\lib\servlet.jar.
If the problem pesists reinstall tomcat on root so that claspath will be c:\jakarta-tomcat-3.2.1\lib\servlet.jar.

VAIBHAV <BR>SCJP
Neelu Bothra
Greenhorn

Joined: Oct 21, 2000
Posts: 23
Try this,posted previously by some one.It helped me.
move/copy the servlet.jar file manually to the %JAVA_HOME%\jre\lib\ext folder.If you do this you donot need to set the classpath for javax.servlet.* packages, as the Java Run-time environment would find it for you.
Tonny Bruckers
Greenhorn

Joined: Sep 15, 2001
Posts: 1
Thank you Neelu Bothra your suggestion solved my problem
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what's wrong with this?