How to Create Java Web Application using Netbeans 8.2

by Didin J. on Jan 08, 2017 How to Create Java Web Application using Netbeans 8.2

Simple guide how to create Java Web Application using Netbeans 8.2 IDE for Java Web development.

With help of Netbeans, web development getting easier. In this how to create Java web application using Netbeans 8.2, we will cover all step by step tutorial from creating the new project to run the web application on the browser. If you need more advance tutorial you can skip this tutorial and head to Spring Boot, MVC, Data and MongoDB CRUD Java Web Application tutorial.

1. Create New Java Web Application Project

To create new Java web application project simply open your Netbeans 8.2 IDE then open File -> New Project. Then choose Java Web in Categories column and Web Application in Projects column. Then click next.

New Project

Give a name your project, mine is "SimpleWebApp". Leave another field as default. Then click next.

Name and Location

Leave default for all fields in Server and Settings then click next.

Server and Settings

In the framework, choose Spring Web MVC and leave default in spring library then click finish.

This creates new java web application wizard generated src folder and web folder which contains core element for building java web application.

2. Simple Spring Web MVC

Now, I will explain a little bit about generated element when creating new java web application. First, open web.xml file, this file contains below code.

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="" xmlns:xsi="" xsi:schemaLocation="">

This web.xml is the core of java web application which defines deployment descriptor element. There's are a lot of components that used in this web.xml, but here we just use context-params, listener, servlet, servlet-mapping, session-config, and welcome-file-list. Those tags are enough for running simple java web application that uses spring web MVC framework (we will not cover Spring Web MVC right now).

Landing page describes in welcome-file-list which this file point to redirect.jsp file contains this codes.

Views should be stored under the WEB-INF folder so that
they are not accessible except through controller process.

This JSP is here to provide a redirect to the dispatcher
servlet but should be the only JSP outside of WEB-INF.
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<% response.sendRedirect("index.htm"); %>

This file just redirect request from root web application to index.html, but actually it's redirect to controller which have default page index.jsp. You can see this in dispatcher servlet.

<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?xml version="1.0" encoding="UTF-8"?> -->
<beans xmlns=""

    <bean class=""/>

    Most controllers will use the ControllerClassNameHandlerMapping above, but
    for the index controller we are using ParameterizableViewController, so we must
    define an explicit mapping for it.
    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
                <prop key="index.htm">indexController</prop>

    <bean id="viewResolver"
          p:suffix=".jsp" />

    The index controller.
    <bean name="indexController"
          p:viewName="index" />


And this is the content of index.jsp.

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Welcome to Spring Web MVC project</title>

        <p>Hello! This is the default welcome page for a Spring Web MVC project.</p>
        <p><i>To display a different welcome page for this project, modify</i>
            <tt>index.jsp</tt> <i>, or create your own welcome page then change
                the redirection in</i> <tt>redirect.jsp</tt> <i>to point to the new
                welcome page and also update the welcome-file setting in</i>

Now, just run your app by choose menu Run -> Run Project or simply click F6 button. It will take long because it's starting Glassfish and Java DB. Now, your web page will look like this.

Java Web Application in Browser

That it's the very simple web application with Java and Netbeans 8.2.