JSP Example using NetBeans IDE :-


The step by step process to create and use JSP files in NetBeans IDE is as follows -

Here we are using NetBeans IDE 8.2.

1- Open the NetBeans and go to File -> New Project, It will open a New Project Window as shown below -



2- From Categories select Java Web option and from Projects select Web Application and click on Next. It will open a new window as follows -



This windows allows you to enter Project name and location, Enter desired project name, here we used “JSPDemo”. You can also change Project storage location if you want, otherwise leaves them as it is. Here we have not changed it. And click on Next
3- This windows allows you to change the server settings. Click in Server drop down list and select desired server. And leave other options as it is.



Note - You can switch to another server from this window if your server does not run for some reasons.
4- Click on Next and next window will ask you for Frameworks. Right now we are not using any framework so leave it as it is, and click on finish.



5- Now our Project has created with index.html default page (welcome page), It will have the following structure -



Note- if you are using NetBeans older versions the default page may be index.jsp.
6- Open index.html page and make changes to it as shown below -

<!DOCTYPE html>
<html>
    <head>
        <title>TODO supply a title</title>
    </head>
    <body>
        <form method="post" action="First.jsp">
            Name - <input type="text" name="t1"><br>
            <input type="submit">
        </form>   
    </body>
</html>

7- Now right click on WebPages folder and go to New -> JSP.



8- It will open a New JSP window. Enter the name of JSP file (Here we are using First)and click Finish.



9 - Now our JSP file has created, Make changes to JSP file as follows -

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>JSP Page</title>
    </head>
    <body>
        <h1>My First JSP Page</h1>
        <%
        String name = request.getParameter("t1");
        out.println("Welcome "+name);  
        %>
   <%-- out is an implicit object of javax.servlet.jsp.JSPWriter class availabel in JSP.  --%>
    </body>
</html>


10 - Now run the project and it will show you following output -



Enter name and press the Submit button -



Download this example - Click Here