Enterprise web programming

Units ENTWA (Level 6) and APSW (Level 7)

Older stuff: creating servlets and JSPs

Creating a new servlet

  1. The easiest way to create a new servlet is to use the servlet wizard. Select File | New File...
    1. In step 1 of the wizard, select category "Web" and file type "Servlet".
    2. In step 2, choose an appropriate class name and an appropriate package name. A good package name is "fred.first" if your name is fred and this is your first project.
    3. In step 3, accept all the defaults. NetBeans will automatically add information about your servlet to the web.xml configuration file.
  2. NetBeans will generate the outline of the new servlet. In most cases, all you need to do is to edit the body of the processRequest method to make it do what you want it to do.
  3. Note that if you create a servlet by another means (e.g. by copying another file), you will need to edit your web.xml file yourself to configure things properly.

Creating a new JSP

  1. The easiest way to create a new JSP is to use the JSP wizard. Select File | New File...
    1. In step 1 of the wizard, select category "Web" and file type "JSP".
    2. In step 2, enter the name of the JSP (without .jsp on the end) and specify the folder you want it to be in.
  2. NetBeans will generate the outline of the new JSP. You then need to edit the page to make it do what you want it to do.
  3. Note that if you create a JSP by another means (e.g. by copying another file), you do NOT need to edit your web.xml file yourself to configure things. A Java web application will find JSPs automatically (unless they are concealed in the WEB-INF folder).

Executing a servlet or JSP

  1. Select Run | Run File or right-click in the source editor and select Run File, or press function key Shift-F6. NetBeans will do the steps listed in "Executing a Project" (above) except that it will invoke the URL that will cause the servlet/JSP to be run. Debugging works in a similar way.
 

Last updated by Dr Jim Briggs of the School of Computing at the University of Portsmouth

 
The enterprise web programming units include some material that was formerly part of the WEB1P and WEB2P units.