testactionsave.java
来自「struts2结合ext参数传递」· Java 代码 · 共 70 行
JAVA
70 行
package com.ufida.struts2.sample;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import com.opensymphony.xwork2.ActionSupport;
public class TestActionSave extends ActionSupport implements Serializable {
private static final long serialVersionUID = -5553501373631684296L;
Map parameters = new HashMap();
public String save(@Bind(key = "firstname", defaultValue = "")
String firstname, @Bind(key = "lastname", defaultValue = "")
String lastname, @Bind(key = "company", defaultValue = "")
String company, @Bind(key = "email", defaultValue = "")
String email, @Bind(key = "time", defaultValue = "")
String time) {
/**
* 取参数,方法一;
*
* String firstname = getFirstName();//getter/setter方法
*/
/**
* 取参数,方法二;
*
* String id =
* ServletActionContext.getRequest().getParameter("firstname");
*/
/**
* 取参数,方法三;
*/
// parameters = ActionContext.getContext().getParameters();
// Iterator it = parameters.entrySet().iterator();
// while (it.hasNext()) {
// Entry testEntry = (Entry) it.next();
// String key = testEntry.getKey().toString();
// String[] values = (String[]) testEntry.getValue();
// String value = values[0];
// System.out.println("key=" + key);
// System.out.println("value=" + value);
// System.out.println("");
// }
// @SuppressWarnings("unused")
// HttpServletResponse response = (HttpServletResponse) ActionContext
// .getContext().get(
// org.apache.struts2.StrutsStatics.HTTP_RESPONSE);
//
// @SuppressWarnings("unused")
// HttpServletRequest request = (HttpServletRequest) ActionContext
// .getContext()
// .get(org.apache.struts2.StrutsStatics.HTTP_REQUEST);
System.out.println("firstname = " + firstname);
System.out.println("");
System.out.println("lastname = " + lastname);
System.out.println("");
System.out.println("company = " + company);
System.out.println("");
System.out.println("email = " + email);
System.out.println("");
System.out.println("time = " + time);
System.out.println("");
return SUCCESS;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?