Getting started with Netbeans 6.9 and how to create a simple web application PART -1


Bookmark and Share

I have used lot of IDE’s but the complete IDE for me is NetBeans , NetBeans is completely free and available for download at http://netbeans.org . NetBeans is a complete opensource IDE with many plugins and has support for many popular languages like PHP and Jruby and Ruby on rails.

This blog entry would be dedicated to JAVA language and how to create simple web applications in JSP and ServletsIn Netbeans there is support for JSF 1.x and 2.0 ,struts 1.3.8 , springs web MVC , hibernate 3.2.5 ;below I have shown how to create a simple application with JSP and servlet. To make your life simple there is a “palette” for HTML which you can use in your JSP’s, HTML, facelets , if it is not coming then you can add it by going to “window” button in the top bar and clicking on palette option in it.



How to create a simple web application in JSP and Servlets using netbeans 6.9.

Go to “File> New Project” in top menu and click on it and you would see the below screen :

Click on the “Java Web” and then go onto “Web Application” and then finally click on the “next” button and you would see the below image
In the above “Project Name” I have taken TestProject as the name of the project and the project would be stored in the “Project Location” directory , the “set as main project” checkbox is clicked so as to make the project a top priority while running or debugging it. Now when you click on “Next” you would get the below image
Now in the above image I have chosen Server for this application as “Glass Fish Server 3.1″ which comes bundled with NetBeans and is the default server for “Netbeans” , there is also provision to add other servers in NetBeans like Tomcat ,weblogic,jboss etc.I have chosen Java EE 6 Web , as j2ee 6 is possible in GlassFish v3 server.Finally click on “Next” button and you would get the below image
The above box is asking for which framwork you want to add in your application as we are making a simple web application comprising of “servlets” and “jsp” , hence we don’t require any framework.Finally click “Finish” and done the project is added in your NetBeans project list and ready for development , you would see the below image in the project explorer:
In the above project Explorer you have got a “index.jsp” page as the default starting page (can change it in the web.xml) located in your WEB-INF folder.your JDK and Glassfish server JAR files would be added automatically. I have added a Servlet in the project by right clicking on the project and clicking on the “servlet” option , you would get the below options when adding a servlet in your project
The above box creates a NewServlet in your project , then click on “Finish” and you would get the below box
In the above box you would get a “add information to deployment descriptor(web.xml)” checkbox just click on it and it would serve two purpose for you create a web.xml for you and add the url mapping of the servlet in web.xml automatically “/NewServlet” is taken as the mapping for the above servlet.Finally click on finish and that would add the servlet in your project, Now you know how to add servlet and JSP would follow a similar trend.
Now as every thing is in place just press “shift+f6″ and that would run the project in your default browser, as index.jsp is the welcome page you would get the view of index.jsp on the browser.

9 Comments

  1. zain says:

    Hi

    The run file command is not working in my netbeans 6.9.1 for the jsp.. When i right click on a jsp the ‘run file’ command is in disabled state. What may be the issue. This is happening only for one project. I am able to execute a jsp of other projects though.

  2. Arpit Sharma says:

    @Zain

    Please be specific as and try shift+f6 if that works , may the project is not added in the webserver check that if it is coming inside the webserver

  3. shamtest says:

    I can’t seem to be able to reach this site from my smartphone!

  4. Shilpi says:

    My Glashfish server is not working.What should I do?

  5. Arpit Sharma says:

    Please elaborate , whts the problem or how did you install it ???

  6. Rakesh says:

    I want runtime create button in jsp for booking

  7. stevan says:

    I have problem with servlets.
    I made HTML named index.html:

    JSP Page

    First number:

    Second number:

    ———————–
    Then java code:

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package Paket;

    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;

    /**
    *
    * @author Expression StevanPivnicki is undefined on line 12, column 14 in Templates/Classes/Class.java.
    */
    public class Zbir extends HttpServlet {
    protected void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
    {
    response.setContentType(“text/html;charset=UTF-8″);
    PrintWriter pw=response.getWriter();
    String prvi=request.getParameter(“first”);
    String drugi=request.getParameter(“second”);
    int a=0,b=0;

    boolean ispravno=true;

    try
    {
    a=Integer.parseInt(first);
    b=Integer.parseInt(second);
    }
    catch (NumberFormatException e)
    {
    ispravno=false;
    }
    int zbir=a+b;

    try
    {
    pw.println(“”);
    pw.println(“”);
    pw.println(“Zbir”);
    pw.println(“”);
    pw.println(“”);
    if(ispravno)
    {
    pw.println(“Zbir je “+zbir);
    }
    else
    {
    pw.println(“Bad input”);
    }
    pw.println(“”);
    pw.println(“”);
    }
    finally
    {
    pw.close();
    }
    }

    protected void doGet(HttpServletRequest request,HttpServletResponse response)
    throws ServletException,IOException
    {
    processRequest(request, response);
    }

    protected void doPost(HttpServletRequest request,HttpServletResponse response)
    throws ServletException,IOException
    {
    processRequest(request, response);
    }

    public String getServletInfo()
    {
    return “Short description”;
    }
    }
    ——————————————-

    And when I run the project everything works fine until I add the numbers and then I get the page that says:

    HTTP Status 404 -

    type Status report

    message

    descriptionThe requested resource () is not available.
    GlassFish Server Open Source Edition 3.1.1

    How to solve that problem ?
    Thanks.

  8. stevan says:

    update:
    index is actually .jsp not .html

  9. amna says:

    I think ap ne JSP page p action ni use kya

Leave a Reply

Get Adobe Flash playerPlugin by wpburn.com wordpress themes