Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java Servlets example using NetBeans 6. Pre-requirements: Install Java JDK 1.6 Install NetBeans IDE 6 (we will use version NetBeans IDE 6.7.1 update 16)

Similar presentations


Presentation on theme: "Java Servlets example using NetBeans 6. Pre-requirements: Install Java JDK 1.6 Install NetBeans IDE 6 (we will use version NetBeans IDE 6.7.1 update 16)"— Presentation transcript:

1 Java Servlets example using NetBeans 6

2 Pre-requirements: Install Java JDK 1.6 Install NetBeans IDE 6 (we will use version NetBeans IDE 6.7.1 update 16) Remember to choose the setup of a web server (GlassFish with GlassFish prelude, Apache Tomcat or both)

3 Create a Web Application File -> New Project -> Java Web -> Web Application Click Next, choose a name and a location for the project. We will call it ITShop Click Next, Choose the Server that you want to use (GlassFish or Apache Tomcat) Click Finish

4 Build the home page An ‘index.jsp’ page is created automatically. Write whatever html code you wish in it. You can also use the tools from the palette on the left. We will write some hyperlink that will call the servlet and pass a value to its doGet method. We also will put a form in that page that includes a text input, a submit button and a reset button.

5

6 Create the servlet Right click the project -> New -> Servlet... Choose a name for the class (we will call it ‘PageCreatorServlet’). Click Next, choose a name for the servlet, (we will use the same name). Note that the check box of ‘Add information to deployment descriptor (web.xml)’ is checked. Click Finish

7 Edit the servlet The ‘PageCreatorServlet’ will be created automatically, including its doGet and doPost methods. It also includes a ‘processRequest’ method that will be called from the doGet and doPost methods. We can write our implementation in the doGet and doPost methods. But instead, here we will write in the processRequest method.

8

9 Note: You can run the servlet alone for testing purposes instead of runing the entire project. Right click the servlet -> Run File. You can also add some parameters to the servlet execution URI (for example: /PageCreatorServlet?DATA=“SW” ). You can also change this execustion URI. To do so, right click the servlet -> Tools -> Set Servlet Execution URI Run the project and test it.

10 Extra parts: Cookies or sessions Database using JDBC


Download ppt "Java Servlets example using NetBeans 6. Pre-requirements: Install Java JDK 1.6 Install NetBeans IDE 6 (we will use version NetBeans IDE 6.7.1 update 16)"

Similar presentations


Ads by Google