Create a project in Netbeans.
Choose a location for your project. If you are creating this project in the
JCCL on the U:
drive, do not create the project in the
webapps folder. I suggest that you create a folder named local
in the cgs4825 directory, and place your projects there.
The web.xml file is located in the Web Pages/WEB-INF folder.
JSPs should be placed in sub-folders of the Web Pages folder. If you want to hide the pages so that they are not directly visible from the web, then place them in sub-folders of the Web Pages/WEB-INF folder.
Servlets should be placed in sub-folders of Source Packages. The package name of a servlet must match the folder location of the .class file. Do not use the default package for a servlet. Always create a sub-folder for a servlet and place the servlet in a package that matches the directory structure.
Create a folder in the Source Packages folder. Create a Java class in the new folder. Copy the following servlet into the file. Change the name of the package to correspond to the name of the folder.
package test; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class TestServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().print("Hello Netbeans"); } }
If you right-click the servlet in the file tree, and select Run, you will get this error:
The solution is to add a servlet mapping for this servlet to the web.xml file.
<servlet> <servlet-name>TestServlet</servlet-name> <servlet-class>test.TestServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>TestServlet</servlet-name> <url-pattern>/test/TestServlet</url-pattern> </servlet-mapping>
The directory that is used in the mapping does not actually exist. There is a directory named WEB-INF/test and another named classes/test, but there is no directory named test in the root of the web application. You may map a servlet to a real directory or to a fictitious directory.
Right-click on the name of the servlet in the file tree and select Run File. You will be prompted for the URL to use to call the servlet. You can add a query string at this time if you want to send some data to the servlet.
When the project is built, a .war file is created in the dist folder. By default, this .war does not include the .java source files. When you upload files to ocelot, I would like the .java source files included in the .war file.
**/*.java
from the Exclude From War File text
box.