Presentation is loading. Please wait.

Presentation is loading. Please wait.

How to Build a Struts Application with JBuilder 9.

Similar presentations


Presentation on theme: "How to Build a Struts Application with JBuilder 9."— Presentation transcript:

1 How to Build a Struts Application with JBuilder 9

2 Target A web page with a single Text Field When user hits the submit button: –If the text field is empty s/he is redirected to the same page –If the text field contains something s/he is presented with another web page containing the string of the text field

3 How it works index.jsp ActionForm Action struts-config.xml (Mapping) quote.jsp Hit submitMapping Checked Target: success Target: failure

4 Quick Steps: JBuilder 9 Add Struts 1.1 Library. Create a new Project. Create a new Web Application. Create a JSP: index.jsp Create ActionForm - LookupForm from JSP Create Action Class – LookupAction Create another JSP – quote.jsp Configure struts-config.xml

5 Add Struts 1.1 Library Unzip Struts 1.1 in a folder. Click Tools-> Configure Libraries in JBuilder Click New Enter Name: Struts 1.1 Add Library Paths ( set the path to struts/lib directory) Click OK From the framework tab select Struts Click OK

6 Create New Project Close all current projects from: File -> Close Project Create a new Project from: File -> New Project Enter Project Name: “hello” Click Finish

7 Create New Web Application Press Ctrl-N Click the Web Tab Select Web Application and Click OK Check the Struts 1.1 Check BOX Select ‘/’ in the Launch URL Combo BOX Click OK

8 Write index.jsp Press Ctrl-N From the Web tab select Java Server Page Click OK Enter name: index.jsp, uncheck the 2 options below Click Next Uncheck Generate Submit Form Check All under the heading Struts 1.1 Click Finish

9 Writing index.jsp Add the following code in the : <html:form action = "/Lookup" name = "lookupForm" type = "hello.LookupForm"> <html:text property = "symbol" />

10 Explanation ‘action’ means the name of the action that happens when the submit button is pressed. ‘type’ means the name of the ActionForm Class. ‘name’ is the identification by which struts- config.xml file knows the ActionForm Class. denotes a textfield whose name is set to symbol. and create a submit and a reset button respectively.

11 Create ActionForm Press Ctrl-N. Select ActionForm. Click OK. In the ActionForm field enter name: LookupForm. Click Next. Click Add from JSP. Select index.jsp. Click OK. Click Finish.

12 Create Action Press Ctrl-N. Select Action. Click OK. In the Action field enter name: LookupAction. Click Next. Action Path: /Lookup Form bean name: lookupForm Scope: request Validate: false Input jsp: /index.jsp Click Finish

13 Writing LookupAction Rename the ‘perform’ method to ‘execute’. The ‘perform’ method is depricated. Add the following code: String str = lookupForm.getSymbol(); if( str == null || str.equals("")) { return actionMapping.findForward("failure"); } httpServletRequest.setAttribute("VALUE",str); return actionMapping.findForward("success"); Delete the line: throw new java.lang.UnsupportedOperationException("Method …");

14 Explanation When the String is not null i.e. the user puts some value in the textfield and hits the submit button we write: httpServletRequest.setAttribute("VALUE",str); return actionMapping.findForward("success"); This roughly means we save the value of str in a variable named VALUE which will be valid for the next page to be displayed. actionMapping.findForward(“success”) searches the struts-config.xml file and finds the page to be displayed for the ‘success’ mapping which we will discuss shortly.

15 Creating quote.jsp Create quote.jsp in the same way we created index.jsp Write the following code in the request.getAttribute(“VALUE”) retrives the value of ‘str’ that we saved in the LookupAction Class.

16 Configure struts-config.xml From the Upper-Left text pane expand struts -> and click struts-config.xml. From the lower-left text pane expand Action-Mappings and Click /Lookup. Click the Forwards tab. Then Click Add. Select it and click edit. Enter name: success Enter path: /quote.jsp In the same way add another entry: Enter name: failure Enter path: /index.jsp

17 That’s All Press F9 to RUN the project.


Download ppt "How to Build a Struts Application with JBuilder 9."

Similar presentations


Ads by Google