Dynamic Web Pages using JSP - Lab Deliverable 12 potx

10 414 1
Dynamic Web Pages using JSP - Lab Deliverable 12 potx

Đang tải... (xem toàn văn)

Thông tin tài liệu

Lab Deliverable 12 Using Actions Part II Write a program to display a forward action demo page Provide a link on the demo page to forward the output to another JSP file Display a message to the user when the user clicks on the link Solution: The files used to run the application are: index.jsp Forward_Demo.jsp Welcome.jsp index.jsp Using Include Actions Using Forward Actions Click here for Forward Action Enter the code in Notepad and save the file as index.jsp in %TOMCAT_HOME%/webapps/ Session19.1 //Forward_Demo.jsp Sample First Document You are being forwarded to this page Save the file as Forward_Demo.jsp in %TOMCAT_HOME%/webapps/Session19.1 Using Actions Ver 1.0 © 2005 Aptech Limited //Welcome.jsp ERROR: Application resources not loaded check servlet container logs for error messages

Save the file as Welcome.jsp in %TOMCAT_HOME%/webapps/Session21 directory Enter the path http://localhost:8080/Session19.1/index.jsp in the address bar A welcome page appears as shown in Figure 19.1 Figure 19.1: Forward Action Page Ver 1.0 © 2005 Aptech Limited JSP and Struts Click on the link on the forward action page to see the implementation of forwardaction The output appears as shown in Figure 19.2 Figure 19.2: Result Page Write a program to provide three colors to the user in a drop-down list When the user selects a color and clicks on Submit button, dispatch the action performed by the user to another page that will display a success message to the user In addition display some text depending on the color selected Hint: Use lookup dispatch action to dispatch the user request and display the output Solution: The files used to run the application are: lookup.jsp Dispatch_Demo.java DispatchDemoActionForm.java //lookup.jsp Using LookupDispatchAction Using Actions Ver 1.0 © 2005 Aptech Limited Using LookupDispatchAction Select an action to dispatch: Red Yellow Green Enter the code in Notepad and save the file as lookup.jsp in %TOMCAT_HOME%/webapps/ Session19.3 //Dispatch_Demo.java package MARKO; import java.io.*; import java.util.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.ServletException; import org.apache.struts.action.*; import org.apache.struts.actions.LookupDispatchAction; public class DispatchDemo extends LookupDispatchAction { public ActionForward red(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { request.setAttribute("msg","Red : Stop."); return mapping.findForward("success"); } Ver 1.0 © 2005 Aptech Limited JSP and Struts public ActionForward yellow(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { request.setAttribute("msg","Yellow : Caution."); return mapping.findForward("success"); } public ActionForward green(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { request.setAttribute("msg","Green : Go."); return mapping.findForward("success"); } protected Map getKeyMethodMap() { Map map = new HashMap(); map.put("MARKO.red", "red"); map.put("MARKO.yellow", "yellow"); map.put("MARKO.green", "green"); return map; } } Save the file as Dispatch_Demo.jsp in the TOMCAT_HOME%/webapps/Session19.3 //DispatchDemoActionForm.java package MARKO; import org.apache.struts.action.ActionForm; public class DispatchDemoActionForm extends ActionForm { private String method = ""; public String getmethod() { return method; } public void setMethod(String method) { this.method = method; } } Using Actions Ver 1.0 © 2005 Aptech Limited Save the file as DispatchDemoActionForm.java in %TOMCAT_HOME%/webapps/Session21 directory Compile the code using command prompt Enter the path http://localhost:8080/Session19.1/lookup.jsp in the address bar The output appears as shown in Figure 19.3 Figure 19.3: Lookup Dispatch Action Page Select a color from the drop down list and click on Submit button The output appears as shown in Figure 21.4 Ver 1.0 © 2005 Aptech Limited JSP and Struts Figure 19.4: Result Page Do It Yourself Create a Web page to provide various products such as banking, Debit cards, and credit Cards to the user The page should allow the user to select a product Display the details about the selected product to the user Solution: The filenames used to run this application are: index.jsp displayOptions.jsp Using Actions Ver 1.0 © 2005 Aptech Limited //index.jsp MARKO MARKO Bank Please select a product from the list: Select a Product Banking Credit Cards Debit Cards //displayOptions.jsp MARKO Options Page Banking

MARKO is Worlds largest bank having a network of about 10,000 branches and extension counters are over 100,000 ATMs MARKO offers a wide range of banking products and financial services to corporate and retail customers through a variety of delivery channels

Credit

MARKO Bank select the online via of sifting

Cards allows you to compare various credit card offers, offer that matches your requirements and apply the web site This certainly beats the alternative through direct mail Debit Cards

MARKO Bank allows you to compare various Debit card offers, select the offer that matches your requirements and apply online via the web site This certainly beats the alternative of sifting through direct mail

Enter the path http://localhost:8080/Session19_4/index.jsp in the address bar The output appears as shown in Figure 19.5 Using Actions Ver 1.0 © 2005 Aptech Limited Figure 19.5: Submit Query Page Select a product, such as Debit Card from the drop down list, and click the Submit Query button The output appears as shown in Figure 19.6 Figure 19.6: Product Detail Page 10 Ver 1.0 © 2005 Aptech Limited JSP and Struts ... lookup .jsp Dispatch_Demo.java DispatchDemoActionForm.java //lookup .jsp Using. ..//Welcome .jsp

Ngày đăng: 14/08/2014, 05:20

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan