• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

my first servlet not Compiling

 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



note : i have installed j2eesdk-1_4_02_2005Q2-windows and also tomcat 6.0


out put is

D:\>javac Welcomserv.java
Welcomserv.java:2: package javax.servlet does not exist
import javax.servlet.*;
^
Welcomserv.java:3: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
Welcomserv.java:4: cannot resolve symbol
symbol : class HttpServlet
location: class Welcomserv
public class Welcomserv extends HttpServlet
^
Welcomserv.java:6: cannot resolve symbol
symbol : class HttpSerletRequest
location: class Welcomserv
public void doGet(HttpSerletRequest req, HttpServletResponse res) throws IOExcep
tion
^
Welcomserv.java:6: cannot resolve symbol
symbol : class HttpServletResponse
location: class Welcomserv
public void doGet(HttpSerletRequest req, HttpServletResponse res) throws IOExcep
tion
^
5 errors


 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to set the classpath to refer servlet-api implementation in order to compile the servlet. (e.g.: javac -cp <Tomcat6Home>/lib/servlet-api.jar <source files>)

Note that you don't need both J2EE SDK (probably the IDE if you are referring to that here may required) and Tomcat to do this...
 
Aniket S. Kulkarni
Ranch Hand
Posts: 87
Android Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@abhay:Vijitha is correct.
Include try,catch block or write ServletException in throws clause .
 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have tried all these methods already .. but still facing same errors
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abhay jain wrote:i have tried all these methods already .. but still facing same errors

Can you show us the command you tried to compile and the errors you get now?
 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry i have closed that window .. but i have compiled it successfully .. actually i tried (as you suggested) a new way and it was as follows

:
i created a batch file to compile every java program [path was : D:\Sun\AppServer\lib\j2ee.jar ]
then i put both java and that batch file in a directory


THANKS A LOT MY FRIEND
 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am sure there some thing that i am missing but what is that ???

D:\>javac -classpath "D:\Program Files\Apache Software Foundation\Tomcat 6.0\lib
\servlet-api.jar" Welcomserv.java



Welcomserv.java:4: cannot access javax.servlet.http.HttpServlet
bad class file: D:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servl
et-api.jar(javax/servlet/http/HttpServlet.class)
class file has wrong version 49.0, should be 48.0
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
public class Welcomserv extends HttpServlet
^
1 error
 
Anupam Dee
Ranch Hand
Posts: 42
Firefox Browser Tomcat Server Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using this

D:\>javac -classpath "D:\Program Files\Apache Software Foundation\Tomcat 6.0\lib" Welcomserv.java
 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anupam Dee wrote:Try using this

D:\>javac -classpath "D:\Program Files\Apache Software Foundation\Tomcat 6.0\lib" Welcomserv.java


not working ................5 errors (same as above)
 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the servlets package in Java™ EE?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic