Learning Center
Plans & pricing Sign in
Sign Out



									Java Servlets example
  using NetBeans 6
   Install Java JDK 1.6
   Install NetBeans IDE 6 (we will use version
    NetBeans IDE 6.7.1 update 16)
       Remember to choose the setup of a web server
        (GlassFish with
        GlassFish prelude,
        Apache Tomcat or both)
    Create a Web Application
   File -> New Project -> Java Web -> Web Application
   Click Next, choose a name and a location for the
    project. We will
    call it ITShop
   Click Next,
    Choose the
    Server that you
    want to use
    (GlassFish or
    Apache Tomcat)
   Click Finish
Build the home page
   An ‘index.jsp’ page is created automatically.
    Write whatever html code you wish in it. You can
    also use the tools from the palette on the left.
       We will write some hyperlink that will call the servlet
        and pass a value to its doGet method.
       We also will put a form in that page that includes a
        text input, a submit button and a reset button.
    Create the servlet
   Right click the project -> New -> Servlet...
   Choose a name for the class (we will call it
    ‘PageCreatorServlet’). Click Next, choose a name
    for the servlet, (we will use the same name). Note
    that the check box
     of ‘Add information
     to deployment
    descriptor (web.xml)’
    is checked.
   Click Finish
Edit the servlet
   The ‘PageCreatorServlet’ will be created
    automatically, including its doGet and doPost
    methods. It also includes a ‘processRequest’
    method that will be called from the doGet and
    doPost methods.
   We can write our implementation in the
    doGet and doPost methods. But instead,
    here we will write in the processRequest
   You can run the servlet alone for testing
    purposes instead of runing the entire project.
       Right click the servlet -> Run File. You can also
        add some parameters to the servlet execution
        URI (for example: /PageCreatorServlet?DATA=“SW”).
       You can also change this execustion URI. To do
        so, right click the servlet -> Tools -> Set Servlet
        Execution URI

   Run the project and test it.
Extra parts:
   Cookies or sessions
   Database using JDBC

To top