• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

my first servlet not Compiling

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 87
Android Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have tried all these methods already .. but still facing same errors
 
Vijitha Kumara
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 42
Firefox Browser Tomcat Server Windows XP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the servlets package in Java™ EE?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic