How to compile a java servlet in netbeans

heyall, just placed the following java code in my src folder in my web app folder in netbeans, anyone tell me how to compile this now? it asks me for a main but not sure exactly what to put
package org.mypackage.chapter1;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ServletOne extends HttpServlet {
  /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   * @param request servlet request
   * @param response servlet response
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    /* TODO output your page here */
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet ServletOne</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet ServletOne at " + request.getContextPath () + "</h1>");
        out.println("Date is: "+ new java.util.Date());
        out.println("</body>");
        out.println("</html>");
    out.close();
  // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  /** Handles the HTTP <code>GET</code> method.
   * @param request servlet request
   * @param response servlet response
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
    processRequest(request, response);
  /** Handles the HTTP <code>POST</code> method.
   * @param request servlet request
   * @param response servlet response
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
    processRequest(request, response);
  /** Returns a short description of the servlet.
  public String getServletInfo() {
    return "Short description";
  // </editor-fold>
}

heyall, just placed the following java code in my src folder in my web app folder in netbeans, anyone tell me how to compile this now?F9
it asks me for a main but not sure exactly what to putCompiling source files never 'asks .. for a main'. You must be trying to execute it. You can't do that outside the servlet container it is intended for
COMPILER ERROR - package javax.servlet.http does not exist
BUT can't even get this far yetSo try compiling it as per your tutorial. Do you understand the difference between 'compile' and 'run'?

Similar Messages

  • How to compile a java file(Servlet) in J2EE v1.3.1

    This is my first time using J2EE instead of J2SE!!HOw to compile a java file in J2ee\bin because there is no javac in j2ee and when i compile in J2se i got
    G:\j2sdk1.4.1_01\bin>javac HelloServlet.java
    HelloServlet.java:2: package javax.servlet does not exist
    import javax.servlet.*;
    This mean it doen;t support servlet in J2se!!so how can /what command to compile a servlet java file in j2ee.Thanks

    You'll need to add the j2ee.jar to your classpath. Usually you'll have to add some jars from your app server to your classpath as well.
    For example (using weblogic):
    javac -classpath c:\java\j2ee\j2ee1.3.1\lib\j2ee.jar;c:\tools\appserver\weblogic\wl7.1\lib\weblogic.jar
    HelloServlet.java

  • How to compile a java file which is in memory?

    how to compile a java file which is in memory?
    such as:
    String s="class MyClass {....}";
    how to compile the string?
    thx

    come on ...That was a perfectly valid solution.
    Do you know how to call the sun.* compiler? If not then search the forums for it. If that interface still exists (which it might not in newer versions) you then will create a string stream from your class and pass it to that.

  • How to compile a java file in J9 for windows mobile 5.0

    I have downloaded J9 for windows mobile 5.0 and need help on how to compile a java file.

    You can compile your source code using J2SE ;)
    may be this is important for you:
    http://awareness.ics.uci.edu/~rsilvafi/pocketPC/index.
    html
    Regards!!!Actually i am using some eSWT related classes also.. so is there any way to compile from the J9 environment using J9 console..

  • How to compile Oracle java strored procedure in Putty

    I have created a java strored procedure , which would be invoked by oracle function.
    This java stored procedure is get compiled via SQL plus. While compiling by the use of putty , it shows lots of compilation error .
    How to compile Oracle java strored procedure in Putty??

    You'll need to add the j2ee.jar to your classpath. Usually you'll have to add some jars from your app server to your classpath as well.
    For example (using weblogic):
    javac -classpath c:\java\j2ee\j2ee1.3.1\lib\j2ee.jar;c:\tools\appserver\weblogic\wl7.1\lib\weblogic.jar
    HelloServlet.java

  • How to compile a Java file

    Hi All,
    I am extending a seeded CO and when I try to compile it in JDev , it asks for many class files the seeded CO imports.
    I have copied all those imported files to my local system and when I try to compile , it still throws an error that some class files used by the classes imported in seeded CO are missing. Now this goes on and on. ( Seems entire server needs to be on my local system).
    Now I decided to port the custom CO to server and compile it there. Even this seems to be a hard task for me as the javac command is not working on the server. It throws following exception
    Exception in thread "main" java.lang.ClassFormatError: com.sun.tools.javac.main. Main (erroneous method access flags)......................................
    Pls suggest how to compile a java file , as downloading entire server classes is a herculean task for me.
    Thanks,
    Srikanth

    Hi Avajain & D.Ram ,
    Thanks for the reply.
    I have downloaded around 70 dependent class files to local system. Now the CO is getting compiled correctly.
    I am extending a region level controller in Payroll page where in I have to default the salary to a predefined value.
    This field is having a VO attribute to it. Now can I go ahead and set a value to the MessageTextInput or should I extend the VO to replace the desired value in the place of already queried value.
    Thanks,
    Srikanth

  • How to compile a java source from a java program

    Hi .
    I would like to know how to compile my java source from inside an execution of a java program.
    Is there another way than rather use :
    Runtime.getRuntime().exec("javac myFile"); ?

    you can and cann't use the source code of javac... or maybe use jikes...

  • How to compile and execute servlet file in j2ee

    In j2ee server when iam compiling servet i am getting error messages like package javax.servlet,and javax.servlet.http does not exist like that.
    i hsve set path like this.and i gave path for j2sdk .
    set CPATH=.;%J2EE_HOME%\lib\j2ee.jar
    javac -classpath %CPATH% AdderServlet.java
    can anybody tell me where to place
    servlet and how to compile it.
    Thank u,
    Renuga

    Make sure that '%J2EE_HOME%\lib\j2ee.jar' is existing. Where is your J2EE_HOME pointing to?
    The best thing I can suggest is, create your own bat file to compile the servlets. Like this,
    Save the lines below as "MyCompiler.bat" file.
    @echo off
    set JDK_HOME=<path to you jdk home upto bin directory>
    set J2EE_HOME=<path to you je22 home>
    set CLASSPATH=.;%J2EE_HOME%\lib\j2ee.jar
    %JDK_HOME%\javac %1
    Use the command,
    MyCompiler AdderServlet.java
    You can improve this MyCompiler.bat further, can add additional jar files to the classpath whenever you want. You can put this bat file in System's path, so that you can invoke it just by the name (MyCompiler) without giving the full path to it (like C:\mydir\MyCompiler).
    Hope this helps.
    Sudha

  • HOW TO INSTALL JDK1.4 ON LINUX PALTFORM AND HOW TO COMPILE A JAVA  FILE

    SIR PLZ KINDLY TELL ME THE PROCDURE OF INSTALL JSDK1.4 ON LINUX .
    1.I HAVE DOWNLOADED IT ONA I HAVE INSTALL IN
    /usr/local
    but
    2: do nt know how set the CALSSPATH and JAVA_HOME(ENV VARIABLES)
    3:HOW TO COMPILE AND RUN THE JAVA FILE(JSP)

    2.
    export JAVA_HOME=/usr/local/jdk1.4.0
    export CLASSPATH=.
    (amending for your set up.)
    Placing these in your /etc/profile file will make them run automatically on log in of a user.
    3.
    You need tomcat, probably, http://jakarta.apache.org.
    Bhav

  • How to compile and run servlets in Eclipse?

    Does somebody known how can I compile and run servlets in Eclipse IDE? I've added and configured Tomcat's plugin. I've created a project with my example servlets source, and I don't know what farther. How do I have compile it without main method? I must add web.xml file from Tomcat's directory into projects in Eclipse and modify it?
    THX Chudzik

    Try googling for "eclipse servlet", surely someone has written instructions.

  • How to compile my java application for Personal Java??

    i write a simple program and want to run it in PJEE.
    program is:
    import java.awt.*;
    public class TestApp {
    public static void main(String[] args) {
    Frame f = new Frame();
    f.pack();
    f.setSize(300,300);
    f.show();
    and i compiled it using JDK1.4
    javac TestApp.javathen i want to test it by using pjava
    pjava TestAppbut i got a error message:
    Error loading class TestApp: Bad major version numberplease tell me what it is mean and how i can debug it, thanks.

    hi, all
    i have resolved my question by myself.
    because:
    |-> personal java
    |
    jdk1.1 -> jdk1.2 -> jdk1.4
    so, i must compile the java file by using jdk1.1.x
    :)

  • How to compile my java?

    How i compile java? when i open javac, it closes in less than a second...

    Make sure that , the CLASSPATH and PATH variables are set in a proper way in Environmentvariables in your system if you are using WINDOWS.
    CLASSPATH=%JAVA_HOME%/lib;
    PATH=%JAVA-HOME%/bin;
    then you have to check in commandprompt by simply typing 'javac'.
    if you get the Options, then it is working properly.
    hope this may help you.
    surendra babu

  • How To Compile Within Java

    Hi Everybody,
    I have a serious problem. I want to compile a Java file withing another Java program, without using the "javac" command or this compiler. Is there any function or class which helps compile a Java source file created withing another Java Class file, So that the new Java source file will not be available to the outside world?
    Thanks,
    TechnoSam.

    I'm pretty sure that you can create a class in memory by passing it a stream of bytecode. From this you could create a new instance and then proceed as normal. However, you're going to need to know how to create that bytecode and I guess that you don't want to have to implement a 'virtual' compiler from scratch. I don't know of anything that can do this for you but I wouldn't be surprised to find that somebody's had a go in the past.
    Perhaps your requirements would be satisfied by compiling your dynamically created source using javac to a temp file and then deleting that once you had instantiated the object? This would do something like what I think that you're after but even then you would need to accept that others would be able to access your class definition by reverse-engineering your source-writing routine, (whether or not it was obsufacated).
    Can you say anymore about what you're trying to achieve?

  • How to compile this java files ?

    I have two files Foo.java & Foo2.java in separate packages.
    PLEASE let me know how to compile these files .
    package XYZ;
    public class Foo {   
    public static void main(String[] args) {    }
    package XYZ.ABCD;
    class Foo2 extends Foo{
    public static void main(String[] args) {     }
                                               }I'm getting .. following error.
    XYZ\ABCD\Foo2.java:3: cannot find symbol
    symbol: class Foo
    class Foo2 extends Foo{
    ^
    1 error

    You need an import statement in Foo2.java.
    import XYZ.Foo;This should come before the package statement.

  • How to compile a java file Dynamically !!!!

    Hi all
    The problem is
    I have a dynamically created java file ,and i want to compile that file dynamically itself. The file name is stored in a string,
    I am using ECLIPSE editor..
    How do i compile this java file (which is stored in a string) dynamically?
    Pls help me, already wasted a lot of time,
    Thanks in advance

    In every Tutorial regarding Dynamic Compilation,
    It is told to import javax.tools.*..
    But i cannot find this package
    I am using jdk1.4, is this the reason?
    Actually the following packages are needed fro this
    import javax.tools.DiagnosticCollector;
    import javax.tools.JavaCompiler;
    import javax.tools.JavaFileObject;
    import javax.tools.StandardJavaFileManager;
    import javax.tools.ToolProvider;
    but i cant finad any..!!!
    Please help me

Maybe you are looking for

  • Photoshop 13.0.6 on mac osx 10.9.5 with AD accounts

    Hi, I take care of 35 imacs at a school and photoshop is often freezing. The students login with their active directory accounts and work with files LOCALLY. Do you know if this setup causes problems? By the way, I was running a setup from a few year

  • Is there a Report to Identify Relationships Between Projects

    Hi, We currently have a problem where people have been copying and pasting activities from other older projects into our current project. In doing this they have also copied over the logic. So the pasted activites are still linked to the older projec

  • Template Problems in DW MX

    I copied and pasted an entire site folder into another to build a CD. When I did that, some of the links didn't follow properly(I used document level links). No big deal, but when I updated the template it no longer askes to update the pages. Did the

  • How do I port triggering?

    I can't connect ot EA Games servers so I wrote them asking what I should. They told me this: It is imperative that you contact your router company or internet service provider. Make sure that your router has the latest firmware. After the firmware up

  • Solaris 10 (5.11) Questions

    I have read many posts that do not seem to relate to my system so I am trying to get answers here. I have several questions regarding root's environment settings, use of LD_LIBRARY_PATH, logging of general errors, and menu configurations. To me there