Pls help me on how to compile servlet

pls i need the help of some kind one to assist me on how to compile and deploy servlet .I'm new to javaEE & am using the javaEE tutorial from sun site.In the first example servlet in d book, after compiling and deploying the greetingServlet and responseServlet and deployed it ,i was told to include a welcome jsp file in d war file. all these i have done but the server always complain of not been able locate d greetingServlet.
i use the netbeans IDE and sun java application server.The greetingServlet & responseServlet codes are these; Pls I don't know what to put in the jsp file
package servlets;
import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
* This is a simple example of an HTTP Servlet.  It responds to the GET
* method of the HTTP protocol.
public class GreetingServlet extends HttpServlet {
    public void doGet(
        HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");
        response.setBufferSize(8192);
        PrintWriter out = response.getWriter();
        // then write the data of the response
        out.println("<html>" + "<head><title>Hello</title></head>");
        // then write the data of the response
        out.println(
                "<body  bgcolor=\"#ffffff\">"
                + "<img src=\"duke.waving.gif\" alt=\"Duke waving\">"
                + "<h2>Hello, my name is Duke. What's yours?</h2>"
                + "<form method=\"get\">"
                + "<input type=\"text\" name=\"username\" size=\"25\">"
                + "<p></p>" + "<input type=\"submit\" value=\"Submit\">"
                + "<input type=\"reset\" value=\"Reset\">" + "</form>");
        String username = request.getParameter("username");
        if ((username != null) && (username.length() > 0)) {
            RequestDispatcher dispatcher = getServletContext()
                                               .getRequestDispatcher(
                        "/response");
            if (dispatcher != null) {
                dispatcher.include(request, response);
        out.println("</body></html>");
        out.close();
    public String getServletInfo() {
        return "The Hello servlet says hello.";
package servlets;
import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
* This is a simple example of an HTTP Servlet.  It responds to the GET
* method of the HTTP protocol.
public class ResponseServlet extends HttpServlet {
    public void doGet(
        HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        // then write the data of the response
        String username = request.getParameter("username");
        if ((username != null) && (username.length() > 0)) {
            out.println("<h2>Hello, " + username + "!</h2>");
    public String getServletInfo() {
        return "The Response servlet says hello.";
}

Here is what you will need to do.
1. Compile the servlets by performing the following steps
1.1 Open a command line in the directory where your servlets are located.
1.2 Type the following commands
1.2.1 javac GreetingServlet.java
1.2.2 javac ResponseServlet.java
Then you should see the .class files for these classes appear in the directory .
Next you will put these class files in the WEB-INF/classes directory.
Once you have done that you will edit your web.xml in the WEB-INF directory to include the two servlets. That code will look something like this
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
     <servlet>
          <servlet-name>GreetingServlet</servlet-name>
          <servlet-class>GreetingServlet</servlet-class>
     </servlet>
     <servlet-mapping>
          <servlet-name>GreetingServlet</servlet-name>
          <url-pattern>/GreetingServlet</url-pattern>
     </servlet-mapping>
     <servlet>
          <servlet-name>ResponseServlet</servlet-name>
          <servlet-class>ResponseServlet</servlet-class>
     </servlet>
     <servlet-mapping>
          <servlet-name>ResponseServlet</servlet-name>
          <url-pattern>/ResponseServlet</url-pattern>
     </servlet-mapping>
</web-app>Once you have done this save the web.xml file and recompile the war file by following these steps
1 open a commandline in the root directory where the servlets are
2 type the following command jar -cvf warFileName.war .
*Note the space and period at the end of the command are not a mistake the space . tells the jar tool to complie the war from the directory you are current in.
Once this command is successfully ran you should see a .war file appear in the directory you are in. Then simply put the war file in your deploy directory of your server and you are finished.
alternatly if you are just doing this for yourself to learn servlets and this is not going to be deployed anywhere then I would just use the W3C's Jigsaw server which does all the work for you all you have to do is compile the servlets and put the class files in the servlets directory and you are done.

Similar Messages

  • Newbie question: how to compile servlet using tomcat?? Thank you

    How to set classpath? How to compile servlet.java?

    jsp is also converted into a servlet .java nd then into a class file
    this is index.jsp
    <%@ page contentType="text/html;charset=windows-1252"%>
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
        <title>untitled</title>
      </head>
      <body>
      </body>
    </html>this is _index.java
    /*@lineinfo:filename=/index.jsp*/
      /*@lineinfo:generated-code*/
    import oracle.jsp.runtime.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.servlet.jsp.*;
    public class _index extends com.orionserver.http.OrionHttpJspPage {
      public final String _globalsClassName = null;
      // ** Begin Declarations
      // ** End Declarations
      public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException {
        response.setContentType( "text/html;charset=windows-1252");
        /* set up the intrinsic variables using the pageContext goober:
        ** session = HttpSession
        ** application = ServletContext
        ** out = JspWriter
        ** page = this
        ** config = ServletConfig
        ** all session/app beans declared in globals.jsa
        PageContext pageContext = JspFactory.getDefaultFactory().getPageContext( this, request, response, null, true, JspWriter.DEFAULT_BUFFER, true);
        // Note: this is not emitted if the session directive == false
        HttpSession session = pageContext.getSession();
        if (pageContext.getAttribute(OracleJspRuntime.JSP_REQUEST_REDIRECTED, PageContext.REQUEST_SCOPE) != null) {
          pageContext.setAttribute(OracleJspRuntime.JSP_PAGE_DONTNOTIFY, "true", PageContext.PAGE_SCOPE);
          JspFactory.getDefaultFactory().releasePageContext(pageContext);
          return;
        int __jsp_tag_starteval;
        ServletContext application = pageContext.getServletContext();
        JspWriter out = pageContext.getOut();
        _index page = this;
        ServletConfig config = pageContext.getServletConfig();
        try {
          // global beans
          // end global beans
          out.write(__oracle_jsp_text[0]);
        catch( Throwable e) {
          try {
            if (out != null) out.clear();
          catch( Exception clearException) {
          pageContext.handlePageException( e);
        finally {
          OracleJspRuntime.extraHandlePCFinally(pageContext,false);
          JspFactory.getDefaultFactory().releasePageContext(pageContext);
      private static final char __oracle_jsp_text[][]=new char[1][];
      static {
        try {
        __oracle_jsp_text[0] =
        "\n<html>\n  <head>\n    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">\n    <title>untitled</title>\n  </head>\n  <body>\n  </body>\n</html>\n".toCharArray();
        catch (Throwable th) {
          System.err.println(th);
    }as you can see.. my IDE converts it into a java class so it can be conpiled to a class file.. by the way i use Oracle Jdeveloper 10g for this pupose of showing you what is happening to your jsp

  • I talk to Siri asking it to call my friend but Siri cannot call. Pls help to advise how to make it work?

    I talk to Siri asking it to call my friend but Siri cannot call. Pls help to advise how to make it work?

    Hello Sonem,
    I found an article with steps you can take to troubleshoot issues with Siri.  I recommend reviewing the full article, but the section titled "Providing Siri with user information" seems particularly useful for the issue you are experiencing:
    iOS: Troubleshooting Siri
    http://support.apple.com/kb/TS4079
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • How to Compile Servlet Java Files

    hello ...
    i am a beginner at JSPs and java servlets ... i have been searchin' hopelessly for the past couple of days. Could someone please guide me on how to compile source files for servlets ... namely how can i include the packages javax.servlet.* since the compiler gives me an error that there is no class name ... I am using jdk1.3
    Do I need to get the java server development kit ... but i cant seem to find it any where on the sun's site ... and do i need to download the j2ee sdk too ...
    As you can gather that i am completely comfused and lost ... After doing programmin with asps and previous java experience, i had thought that the migration to a java platform on would be a breeze but the lack of any solid documentation which addresses the above questions is dampenin my spirits ... and the cryptic documentation with tomcat doesnt help either. :)
    pleaze reply soon ... i have to implement a project for my company ... otherwise i would have to put servlets and jsp back in the closet and return back to asp.

    Try http://java.sun.com/j2ee/docs.html specifically, the links on that page called Download Instructions, Installation Instructions, Java Servlets Tutorial and JavaServer Pages QuickStart Guide
    By the way, J2EE SDK's reference implementation is based on Tomcat itself but is more than a web container.

  • How to Compile servlet files in weblogic

    Hi,
    I would like to know how i can compile the servlet files to deploy in weblogic.
    I searched for servlet.jar or servlet-api.jar files in my weblogic 8.1 installed folder. Could not find it to set the classpath.
    Please help.

    You need to use weblogic.jar for Weblogic 8.1. It should be present under server\lib subdirectory in Weblogic installation directory.

  • How to compile servlet with Edit Plus?

    Hi
    I am writing a Java servlet in EditPlus and am wondering how to include the servlet.jar file so that EditPlus knows where the javax.servlet.*, etc classes are. I suppose this is an EditPlus specific question so sorry about that but I didn't know who else to ask other than EditPlus themselves of course and I think I have tried that once.
    I have read replies on this forum about changing the classpath but I dont think that that is what I need to do here and if it is I dont know what I should be writing as I am not using the jdk.
    If anyone can help me at all I would be very grateful.
    Thanks

    Yes, I have also compiled Java files from EditPlus. Using the facilities for configuring 'User Tools' in EditPlus.
    EditPlus runts programs(javac in the current context) in a separate environment(separate DOS command).
    I just compiled, from EditPlus, some Java file of mine that uses something from the servlet API. It compiled just fine. I did not do any classpath or other setup on classpath lines inside EditPlus. I guess, EditPlus inherits the existing CLASSPATH(all environment settings in fact) setting from your environment and thereafter aslo passes it along to the separate command prompt it opens to run user configured tools to run.

  • Urgent! Pls help me! Can't compile any *.java files

    I am a new user to Java2SDK. I am using Win2K sever and I have installed Java2SDK1.4.0 in D drive. When I compile any *.java files, a message " 'javac' is not recognized as an internal or external command, operable program or batch file" appears. How can I solve this problem?
    Please help me. I am busy with my homework. Thank you very much.

    In your PATH variable include %JAVA_HOME%\bin;
    For example:
    C:\jdk1.4\bin;

  • How to compile servlet

    Hi,
    Now i create my first servlet, I want to compile and run it.
    I downloaded J2EE SDK but I don't know where is the jar file which contain servlet classes.
    thanks,
    Shimaa

    My friend , From your post it seems you have kickstarted your career in JSP and Servlet Technology. Compiling a Servlet is as simple as mud if you are using Tomcat [Best Server for Beginners in this field]
    For Tomcat :
    If you downloaded the tomcat server from Apache website and if you extracted to your c:\ , then following things have to setted up in the environmental variables of your machine (Right click Mycomputer ->Advanced->Environmental Variables)
    1: CATALINA_HOME : C:\jakarta-tomcat-5.0.16
    2:CLASSPATH : C:\jakarta-tomcat-5.0.16\common\lib\servlet-api.jar;C:\jakarta-tomcat-5.0.16\common\lib\jsp-api.jar
    3:JAVA_HOME : C:\j2sdk1.4.0
    4:path : c:\j2sdk1.4.0\bin;C:\jakarta-tomcat-5.0.16\bin..
    Hope this helps...

  • Please help!! how to compile/run  Swing

    Hi all! please tell me how can I compile and run Swing classes in
    Forte.
    I have a window frame (WindowA class)that calls another window frame(windowB class)
    They are stored in the same directory but saved with different name.
    Please help..
    thanks in advance

    oh i just read your other post. you can call another class simply by
    just writing
    newClass x = new newClass();
    or just :
    new newClass();
    works i think :)
    put that line in the actionPerformed method,
    and if newClass() has a frame, it'll come up in a new window.
    You did handle the button with an ActionListener right?

  • How to compile servlets

    well,actually the problem arises this way.i have installed the new version j2ee sdk which even contains j2se1.5.now when i compile the servlet program it says the package import http.servlet.*; does not exists.i even had set the classpath as C:\Sun\AppServer\jdk\lib\dt.jar;C:\Sun\AppServer\jdk\lib\tools.jar;C:\bea\weblogic81\server\lib\weblogic.jar;C:\bea\weblogic81\server\lib\webservices.jar;.;
    b'coz i m using web-server as weblogic so i even included it in the classpath.now wats the problem for compilation ,i tried all sorts of things but unable to solve.so plz some1 do post the solution as i m preparing for SWCD.

    well,actually the problem arises this way.i have
    installed the new version j2ee sdk which even
    contains j2se1.5.of course - jee cannot exist without jse.
    now when i compile the servlet
    program it says the package import http.servlet.*;
    does not exists.Because you need that package in your CLASSPATH and it's not, according to the compiler.
    i even had set the classpath as
    C:\Sun\AppServer\jdk\lib\dt.jar;C:\Sun\AppServer\jdk\l
    ib\tools.jar;C:\bea\weblogic81\server\lib\weblogic.jar
    ;C:\bea\weblogic81\server\lib\webservices.jar;.;I'm confused - you have WebLogic 8.1 as your JEE server. Why do you need the one from Sun? (Answer: You don't.)
    b'coz i m using web-server as weblogic so i even
    included it in the classpath.now wats the problem for
    compilation ,i tried all sorts of things but unable
    to solve.so plz some1 do post the solution as i m
    preparing for SWCD.You're preparing for SWCD and you don't know how CLASSPATH works? Oh, my.
    You should not use a system environment variable CLASSPATH. (I don't have one.) Use the -classpath option on javac.exe and java.exe when you compile and run, respectively. You should set the CLASSPATH each and every time you compile and run, because it changes with every application you write.
    If this becomes tedious, either put it in a script or learn how to use Ant.
    %

  • How to compile servlet reply asap

    Hi all,
    I have jdk1.2.2 installed in my pc and the class path i set is c:\jdk1.2.2\bin
    And I have jsdk2.0 for servlet what are the steps i have to follow in this situation. kindly provide me a prompt solution to compile my new servlet. When i compile my first servlet it gives error cannot resolve symbol javax.servlet.* and cannot Resolve symbol HttpServletRequest req,HttpServletResponse res
    needs solution asap
    san

    hi man
    first of all u know that servlet package is j2ee.jar.
    second i think that javax.servlet.* is in java1.4...(java 2)
    plz check that ....
    if u r facing that canj not resolve it, it means that the package is not imported yet.
    finally set path=.../bin not class path
    in fact it will be
    c:\SET PATH=//bin directory
    cL\SET CLASSPATH=//CLASS DIRECTORY
    do mail mail me if u faced problem
    gd luck

  • How to compile servlet in tomcat

    hi,i have wrote the servlet java file, and then i have saved that
    inside webapp/webinf/class and then i tried to compile
    that it shows error during compilation like javax.servlet.*;
    package does not exit like that.

    hi,i have wrote the servlet java file, and then i
    have saved that
    inside webapp/webinf/class and then i tried to
    compile
    that it shows error during compilation like
    javax.servlet.*;
    package does not exit like that.
    hi,i have wrote the servlet java file, and then i
    have saved that
    inside webapp/webinf/class and then i tried to
    compile
    that it shows error during compilation like
    javax.servlet.*;
    package does not exit like that.check out whether you have written this line while listing packages
    import javax.servlet.*;
    The error you are getting during compilation clearly mentions that the server is unable to find the package that it has to refer to.

  • Pls help...How to pass a executed value to a variable?

    hi everyone im new here..
    ok im having prob in passing the executed value of a string into a variable for me to manupulate the value. sample codes as below :
    declare @Str varchar(500)
    declare @Str1 varchar(50)
    declare @Int varchar(50)
    declare @Str2 varchar(50)
    set @Str1 = 'where ET.isVerified = 1'
    set @Str = 'select sum(ET.Sundries+ET.Entertainment+ET.BalReimbursement+ET.Fee+ET.TrainerCharges+ET.SeminarPack+ET.Food+ET.Accomodation+ET.Flight) from ExpensesTransactions ET ' + @Str1
    EXEC(@Str)
    Answer : 16935.00
    so now i want to pass the output(Answer) into a variable so that i can insert the value into a table. anyone can help me in this thing . thank you so much..
    regards
    -nash-

    hi Jurek
    thanx for ur help dude, i change as what u said but i got this error msg "Incorrect syntax near '@Answer'"
    declare @Str varchar(500)
    declare @Str1 varchar(50)
    declare @Int varchar(50)
    declare @Str2 varchar(50)
    declare @Answer varchar(50)
    set @Str1 = 'where ET.isVerified = 1'
    set @Str = ' BEGIN select sum(....) INTO @Answer From ExpensesTransactions ET ' + @Str1 + ' END;'
    EXEC(@Str)
    print @Answer
    but then i change the script abit to 'Begin select....' + @Answer + ' From ..' + @Str1 + 'END;'...this time i got no error msg but there is no value in variable @Answer...
    thanx everyone
    - nash -

  • Urgent pls help!! How to search for an object in vectors?

    Hi,
    I heard that a Vector can store an object right?
    So lets say I created an object called Student that has the attributes: id, name, sex, age
    1) Is vector able to store many students with all these attributes? cos the examples i have seen so far vector only seems to store one attribute
    2) how do i search for sumthin in a vector? let's say i want to key in the student id or his name and find tt student's record to display it?
    thx!

    so sorry... apparantly i didnt copy the last few brackets..
    ===============================================================
    import java.io.*;
    import java.util.*;
    class AddReservation
         static BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in));
         //Main Method
         public static void main (String[]args)throws IOException
              String custName, comments;
              int covers, date, startTime, endTime;
              int count = 0;
              //User can only add one reservation at a time
              do
                   //Create a new reservation
                   Reservation oneReservation=new Reservation();                         
                   System.out.println("Please enter customer's name:");
                   System.out.flush();
                   custName = stdin.readLine();
                   oneReservation.setcustName(custName);
                   System.out.println("Please enter number of covers:");
                   System.out.flush();
                   covers = Integer.parseInt(stdin.readLine());
                   oneReservation.setCovers(covers);
                   System.out.println("Please enter date:");
                   System.out.flush();
                   date = Integer.parseInt(stdin.readLine());
                   oneReservation.setDate(date);
                   System.out.println("Please enter start time:");
                   System.out.flush();
                   startTime = Integer.parseInt(stdin.readLine());
                   oneReservation.setstartTime(startTime);
                   System.out.println("Please enter end time:");
                   System.out.flush();
                   endTime = Integer.parseInt(stdin.readLine());
                   oneReservation.setendTime(endTime);
                   System.out.println("Please enter comments, if any:");
                   System.out.flush();
                   comments = stdin.readLine();
                   oneReservation.setComments(comments);
                   count++;
              while (count<1);
              class Reservation
              private Reservation oneReservation;
              private String custName, comments;
              private int covers, startTime, endTime, date;
              //Default constructor
              public Reservation()
              public Reservation(String custName, int covers, int date, int startTime, int endTime, String comments)
                   this.custName=custName;
                   this.covers=covers;
                   this.date=date;
                   this.startTime=startTime;
                   this.endTime=endTime;
                   this.comments=comments;
              //Setter methods
              public void setcustName(String custName)
                   this.custName=custName;
              public void setCovers(int covers)
                   this.covers=covers;;
              public void setDate(int date)
                   this.date=date;
              public void setstartTime(int startTime)
                   this.startTime=startTime;
              public void setendTime(int endTime)
                   this.endTime=endTime;
              public void setComments(String comments)
                   this.comments=comments;
              //Getter methods
              public String getcustName()
                   return custName;
              public int getCovers()
                   return covers;
              public int getDate()
                   return date;
              public int getstartTime()
                   return startTime;
              public int getendTime()
                   return endTime;
              public String getComments()
                   return comments;
              //Display the current reservation
              //public void displayReservation()
         //          System.out.println(custName.getcustName());
         //          System.out.println(covers.getCovers());
         //          System.out.println(date.getDate());
         //          System.out.println(startTime.getstartTime());
         //          System.out.println(endTime.getendTime());
         //          System.out.println(comments.getComments());
    ===============================================================
    import java.io.*;
    import java.util.*;
    class searchBooking
         static BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in));
         public static void main (String[]args)throws IOException
              int choice, date, startTime;
              String custName;
                   //Search Menu
                   System.out.println("Search By: ");
                   System.out.println("1. Date");
                   System.out.println("2. Name of Customer");
                   System.out.println("3. Date & Name of Customer");
                   System.out.println("4. Date & Start time of reservation");
                   System.out.println("5. Date, Name of customer & Start time of reservation");
                   System.out.println("Please make a selection: ");          
                   //User keys in choice
                   System.out.flush();
                   choice = Integer.parseInt(stdin.readLine());
                   if (choice==1)
                        System.out.println("Please key in Date (DDMMYY):");
                        System.out.flush();
                        date = Integer.parseInt(stdin.readLine());
                   else if (choice==2)
                             System.out.println("Please key in Name of Customer:");
                             System.out.flush();
                             custName = stdin.readLine();
                   else if (choice==3)
                             System.out.println("Please key in Date (DDMMYY):");
                             System.out.flush();
                             date = Integer.parseInt(stdin.readLine());
                             System.out.println("Please key in Name of Customer:");
                             System.out.flush();
                             custName = stdin.readLine();
                   else if (choice==4)
                             System.out.println("Please key in Date (DDMMYY):");
                             System.out.flush();
                             date = Integer.parseInt(stdin.readLine());
                             System.out.println("Please key in Start time:");
                             System.out.flush();
                             startTime = Integer.parseInt(stdin.readLine());
                   else if (choice==5)
                             System.out.println("Please key in Date (DDMMYY):");
                             System.out.flush();
                             date = Integer.parseInt(stdin.readLine());
                             System.out.println("Please key in Name of Customer:");
                             System.out.flush();
                             custName = stdin.readLine();
                             System.out.println("Please key in Start time:");
                             System.out.flush();
                             startTime = Integer.parseInt(stdin.readLine());
              public void           
    }

  • Pls. pls help me on how to use my eprint. i'm using HP photosmart K510 and i don't have a router.

    Hello everyone..I tried setting up an ad hoc network and connect it with my printer but it says I have to give an SSID. I don't know where to retrieve it. I am using a genuine HP printer. Please somebody help me... please..

    Hey jhong0219,
    1. To setup an Ad Hoc connection, you need to restore the network defaults on the printer.
    2. Now you need to make sure the wireless radio is on.
    3. Now you can search for wireless networks on the mobile device and look for the network that starts with HP.(Possibly the hpc510 network?)
    4. You can now print to the printer from the mobile device.
    Although I am an HP employee, I am speaking for myself and not for HP.
    If I have resolved your issue, feel free to provide Kudos and make sure you mark this thread as solution provided.

Maybe you are looking for

  • Why aren't format() and parseDouble() or parseInt() compatible??

    Hello, I display numbers to the user in their default locale format with: NumberFormat.getInstance().format(number) For example, here in the United States, I get a string with commas separating every 3 digits. However, when the user naturally wants t

  • Connecting to two networks

    At work I have a windows PC connected to a secure network (ethernet), and an iMac connected to the internet via wifi. I have to give these two machines access to the same files (rather large media files). Moving a USB-disk is a bit of a hassle. Can I

  • Best Way to Handle IOException in ServerSocket

    What is the best way to handle IOException thrown by ServerSocket's accept() method?

  • SAP WAS Installation

    This is my first Netweaver installation. Anyone knows in which CD/DVD is the SAP:J2EE-CD:630:::I386:* ? Thanks

  • Compilations in iTunes 7

    my compilations are all listed in the compilations category (good!) AND separately listed under every single artist which in on them (BAD!). iTunes 6 has put all my albums marked as compilation only into the compilations category. is this a bug?   Wi