1 / 13

RequestDispatcher in JSP – EEMag Sample

RequestDispatcher in JSP – EEMag Sample. Employee Management Version 0.1. Objectives. Using RequestDispatcher in JSP <jsp:forward page=“…"/> Get parameters of the form in JSP request.getParameter("List"). Home page – menu.jsp. Go to Add page. Go to List page. List page – list.jsp.

kedem
Télécharger la présentation

RequestDispatcher in JSP – EEMag Sample

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. RequestDispatcher in JSP – EEMag Sample Employee Management Version 0.1

  2. Objectives • Using RequestDispatcher in JSP • <jsp:forward page=“…"/> • Get parameters of the form in JSP • request.getParameter("List")

  3. Home page – menu.jsp Go to Add page Go to List page

  4. List page – list.jsp

  5. Add page – add.jsp

  6. View page – view.jsp

  7. Source code: menu.jsp <html> <body> <form action="process.jsp"> <input type="Submit" name="List" value="List"> &nbsp;&nbsp; <input type="Submit" name="Add" value="Add"> &nbsp;&nbsp; </form> </body> </html>

  8. Source code: process.jsp <%! String nextPage; %> <% if (request.getParameter("List") != null) { System.out.println("Clicked List button"); nextPage = "list.jsp"; } else if (request.getParameter("Add") != null ) { System.out.println("Clicked List button"); nextPage = "add.jsp"; } %> <jsp:forward page="<%= nextPage %>"/>

  9. Source code: list.jsp <html> <body> <a href="menu.jsp">Go to Menu</a> <br/> <h1>Listing Employes:</h1> <table border="1" cellspacing="0"> <tr> <th>Full name</th> <th>Sex</th> <th>Adress</th> </tr> <tr> <td>NNNN</td> <td>NNNN</td> <td>NNNN</td> </tr> </table> </body> </html>

  10. Source code: add.jsp (1) <html> <body> <a href="menu.jsp">Go to Menu</a> <form action="add.jsp"> Name*:&nbsp;&nbsp;<input type="input" name="fullName" value=""> <br/> Sex:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select name="sex"> <option></option> <option name="male">Male</option> <option name="female">Female</option> </select> <br/> Address:<textarea name="address" cols="10" rows="3"></textarea> <br/><br/> <input type="Submit" name="Create" value="Create"> </form> </body>

  11. Source code: add.jsp (2) <%! boolean createSuccess; %> <% // Clicked on Add button createSuccess = false; if ((request.getParameter("Create") != null) && (!"".equals(request.getParameter("fullName")))) { String fullName = request.getParameter("fullName"); String sex = request.getParameter("sex"); String address = request.getParameter("address"); // Logging for debug System.out.println("eemag.add: fullName = " + fullName); System.out.println("eemag.add: sex = " + sex); System.out.println("eemag.add: address = " + address); createSuccess = true; } %> <% if (createSuccess) { %> <%-- Forward to the view page --%> <jsp:forward page="view.jsp"/> <% } %> </html>

  12. Web Application Descriptor – web.xml <?xml version="1.0"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <display-name>Employee Management</display-name> <welcome-file-list> <welcome-file>menu.jsp</welcome-file> </welcome-file-list> </web-app>

  13. Pack the web application into war file • Open the window command line by going to menu Start | Run. Then execute “cmd” comand. • Change the working directory into the folder that contains the web application • Execute the comand: jar -cvf eemag01.war . (Note: run “jar” without any argument to view helps)

More Related