📄 registeraction.java.svn-base
字号:
package com.test.actions;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class RegisterAction extends ActionSupport implements
ServletRequestAware, ServletResponseAware {
private String userName = "";
private String password = "";
private int age = 0;
private HttpServletRequest request = null;
private HttpServletResponse response = null;
@SuppressWarnings("unchecked")
@Override
public String execute() throws Exception {
/* System.out.println("方法执行");
ActionContext.getContext().put("demo", "Panda逍遥");
Map session = ActionContext.getContext().getSession();
session.put("OK", "OK!!!");*/
HttpSession session = this.request.getSession();
session.setAttribute("OK", "Panda逍遥");
request.setAttribute("demo", "Panda逍遥");
Cookie cookie = new Cookie("userName", this.getUserName());
cookie.setMaxAge(100);
this.response.addCookie(cookie);
return Action.SUCCESS;
}
@SuppressWarnings("unchecked")
@Override
public void validate() {
if (this.getUserName() == null || ("".equals(this.getUserName()))) {
// this.addFieldError("userName", "用户名不能为空!");
this.addActionError(this.getText("username.invalid"));
} else if (this.getUserName().length() < 6) {
List list = new ArrayList();
list.add("UserName");
this.addActionError(this.getText("username.invalid", list));
}
if (this.getPassword() == null || ("".equals(this.getPassword()))) {
// this.addFieldError("password", "密码不能为空!");
this.addActionError(this.getText("password.invalid"));
}
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
public void setServletResponse(HttpServletResponse response) {
this.response = response;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -