Last modified by Ken McWilliams on 2012/03/10 01:50

From version Icon 3.1 Icon
edited by Ken McWilliams
on 2012/03/03 23:17
Change comment: There is no comment for this version
To version 1.1 Icon
edited by Ken McWilliams
on 2012/03/03 23:02
Change comment: There is no comment for this version

Summary

Details

Icon Page properties
Content
... ... @@ -52,46 +52,3 @@
52 52  To access this action: http:~/~/localhost:8080/Example/enter-name
53 53  
54 54  === Example 2 - Process form and display results ===
55 -
56 -We need to create an action to process the name from the above example. We know that we must put this action in a package which contains the name "action", "struts" or "struts2".
57 -
58 -**Create a package called**: com.example.action (really the package structure before ".action" can be what ever you want)
59 -
60 -**Create a file in this package called**: ProcessForm.java
61 -
62 -**Add the following source**:
63 -
64 -package com.example.action;
65 -\\import com.opensymphony.xwork2.ActionSupport;
66 -\\public class ProcessForm extends ActionSupport{
67 - private String name; ~/~/If this was public we could ommit the getters/setters
68 -\\ @Override
69 - public String execute(){
70 - ~/~/processing goes here
71 - ~/~/lets do something really simple like adding Hello to the name
72 - name = "Hello, " + name + "!";
73 - return SUCCESS;
74 - }
75 -\\ public String getName() {
76 - return name;
77 - }
78 -\\ public void setName(String name) {
79 - this.name = name;
80 - }
81 -}
82 -
83 -**Create the JSP for this action**: /WEB-INF/content/process-form **and add the following content**
84 -
85 -<%@taglib prefix="s" uri="/struts-tags"%>
86 -<%@page contentType="text/html" pageEncoding="UTF-8"%>
87 -<!DOCTYPE html>
88 -<html>
89 - <head>
90 - <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
91 - <title>Display Processing Example</title>
92 - </head>
93 - <body>
94 - <h1>Display Processing Example</h1>
95 - <s:property value="name"/>
96 - </body>
97 -</html>