struts2 零配置代码
来源:互联网 发布:网络电玩游戏 编辑:程序博客网 时间:2024/05/23 01:12
package com.ss.hria.action;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.mapper.ActionMapping;
import com.opensymphony.xwork2.ActionSupport;
import com.ss.hria.util.StringUtil;
public class BaseAction extends ActionSupport {
public BaseAction() {
}
private Long bizId;
/**
* 附件的大小,默认限制为8M
*/
protected static int fileSize = 8192;
/**
* defalut current year
*/
protected static int yearAim = Calendar.getInstance().get(Calendar.YEAR);;
/**
* year bound,+-10
*/
protected static int yearBound = 5;
private List<String> yearList;
private List<String> monthList;
public List<String> getYearList() {
if (yearList == null) {
yearList = new ArrayList<String>();
}
for (int year = yearAim - yearBound; year < yearAim + yearBound; year++) {
yearList.add("" + year);
}
return yearList;
}
public void setYearList(List<String> yearList) {
this.yearList = yearList;
}
public List<String> getMonthList() {
if (monthList == null) {
monthList = new ArrayList<String>();
}
for (int j = 1; j < 13; j++) {
if (j < 10) {
monthList.add("0" + String.valueOf(j));
} else {
monthList.add(String.valueOf(j));
}
}
return monthList;
}
public void setMonthList(List<String> monthList) {
this.monthList = monthList;
}
/**
* Save the message in the session, appending if messages already exist
*
* @param msg
* the message to put in the session
*/
@SuppressWarnings("unchecked")
protected void saveMessage(String msg) {
List messages = (List) getRequest().getSession().getAttribute("messages");
if (messages == null) {
messages = new ArrayList();
}
messages.add(msg);
getRequest().getSession().setAttribute("messages", messages);
}
/**
* Convenience method to get the Configuration HashMap from the servlet
* context.
*
* @return the user's populated form from the session
*/
@SuppressWarnings("unchecked")
protected Map getConfiguration() {
Map config = (HashMap) getSession().getServletContext().getAttribute("appConfig");
// so unit tests don't puke when nothing's been set
if (config == null) {
return new HashMap();
}
return config;
}
/**
* Convenience method to get the request
*
* @return current request
*/
protected HttpServletRequest getRequest() {
return ServletActionContext.getRequest();
}
/**
* Convenience method to get the response
*
* @return current response
*/
protected HttpServletResponse getResponse() {
return ServletActionContext.getResponse();
}
/**
* Convenience method to get the session. This will create a session if one
* doesn't exist.
*
* @return the session from the request (request.getSession()).
*/
protected HttpSession getSession() {
return getRequest().getSession();
}
public static final String CUSTOM = "custom";
private String forwardUrl;
public String getForwardUrl() {
return forwardUrl;
}
public void setForwardUrl(String forwardUrl) {
this.forwardUrl = forwardUrl;
}
public String customMethod(String method) {
return custom(null, method, null);
}
public String custom() {
return custom(null, null, null);
}
public String custom(String prefix, String method, String suffix) {
String msuffix = "";
if (StringUtil.isRealEmpty(prefix)) {
prefix = "/WEB-INF/content/";
}
if (StringUtil.isRealEmpty(suffix)) {
suffix = ".jsp";
}
if (!suffix.startsWith(".")) {
suffix = "." + suffix;
}
ActionMapping actionMapping = ServletActionContext.getActionMapping();
if (StringUtil.isRealEmpty(method)) {
method = actionMapping.getMethod();
}
if ("add".equals(method) || "save".equals(method) || "load".equals(method) || "edit".equals(method)
|| "update".equals(method)) {
method = "form";
} else if ("view".equals(method)) {
method = "view";
} else if ("list".equals(method)) {
method = "list";
} else if ("find".equals(method)) {
method = "find";
} else if ("search".equals(method)) {
method = "search";
} else if ("query".equals(method)) {
method = "query";
}
String tempForwardUrl = StringUtil.connectURL(prefix, actionMapping.getNamespace(), actionMapping.getName(),
method + suffix);
return custom(tempForwardUrl);
}
@Override
public String input() {
return customMethod("add");
}
public String custom(String forwardUrl) {
return _custom(0, forwardUrl);
}
public String customRedirect(String forwardUrl) {
return _custom(2, forwardUrl);
}
public String customRedirectAction(String forwardUrl) {
return _custom(3, forwardUrl);
}
private String _custom(int type, String forwardUrl) {
setForwardUrl(forwardUrl);
return CUSTOM + (type < 1 ? "" : type);
}
public Long getBizId() {
return bizId;
}
public void setBizId(Long bizId) {
this.bizId = bizId;
}
}
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.mapper.ActionMapping;
import com.opensymphony.xwork2.ActionSupport;
import com.ss.hria.util.StringUtil;
public class BaseAction extends ActionSupport {
public BaseAction() {
}
private Long bizId;
/**
* 附件的大小,默认限制为8M
*/
protected static int fileSize = 8192;
/**
* defalut current year
*/
protected static int yearAim = Calendar.getInstance().get(Calendar.YEAR);;
/**
* year bound,+-10
*/
protected static int yearBound = 5;
private List<String> yearList;
private List<String> monthList;
public List<String> getYearList() {
if (yearList == null) {
yearList = new ArrayList<String>();
}
for (int year = yearAim - yearBound; year < yearAim + yearBound; year++) {
yearList.add("" + year);
}
return yearList;
}
public void setYearList(List<String> yearList) {
this.yearList = yearList;
}
public List<String> getMonthList() {
if (monthList == null) {
monthList = new ArrayList<String>();
}
for (int j = 1; j < 13; j++) {
if (j < 10) {
monthList.add("0" + String.valueOf(j));
} else {
monthList.add(String.valueOf(j));
}
}
return monthList;
}
public void setMonthList(List<String> monthList) {
this.monthList = monthList;
}
/**
* Save the message in the session, appending if messages already exist
*
* @param msg
* the message to put in the session
*/
@SuppressWarnings("unchecked")
protected void saveMessage(String msg) {
List messages = (List) getRequest().getSession().getAttribute("messages");
if (messages == null) {
messages = new ArrayList();
}
messages.add(msg);
getRequest().getSession().setAttribute("messages", messages);
}
/**
* Convenience method to get the Configuration HashMap from the servlet
* context.
*
* @return the user's populated form from the session
*/
@SuppressWarnings("unchecked")
protected Map getConfiguration() {
Map config = (HashMap) getSession().getServletContext().getAttribute("appConfig");
// so unit tests don't puke when nothing's been set
if (config == null) {
return new HashMap();
}
return config;
}
/**
* Convenience method to get the request
*
* @return current request
*/
protected HttpServletRequest getRequest() {
return ServletActionContext.getRequest();
}
/**
* Convenience method to get the response
*
* @return current response
*/
protected HttpServletResponse getResponse() {
return ServletActionContext.getResponse();
}
/**
* Convenience method to get the session. This will create a session if one
* doesn't exist.
*
* @return the session from the request (request.getSession()).
*/
protected HttpSession getSession() {
return getRequest().getSession();
}
public static final String CUSTOM = "custom";
private String forwardUrl;
public String getForwardUrl() {
return forwardUrl;
}
public void setForwardUrl(String forwardUrl) {
this.forwardUrl = forwardUrl;
}
public String customMethod(String method) {
return custom(null, method, null);
}
public String custom() {
return custom(null, null, null);
}
public String custom(String prefix, String method, String suffix) {
String msuffix = "";
if (StringUtil.isRealEmpty(prefix)) {
prefix = "/WEB-INF/content/";
}
if (StringUtil.isRealEmpty(suffix)) {
suffix = ".jsp";
}
if (!suffix.startsWith(".")) {
suffix = "." + suffix;
}
ActionMapping actionMapping = ServletActionContext.getActionMapping();
if (StringUtil.isRealEmpty(method)) {
method = actionMapping.getMethod();
}
if ("add".equals(method) || "save".equals(method) || "load".equals(method) || "edit".equals(method)
|| "update".equals(method)) {
method = "form";
} else if ("view".equals(method)) {
method = "view";
} else if ("list".equals(method)) {
method = "list";
} else if ("find".equals(method)) {
method = "find";
} else if ("search".equals(method)) {
method = "search";
} else if ("query".equals(method)) {
method = "query";
}
String tempForwardUrl = StringUtil.connectURL(prefix, actionMapping.getNamespace(), actionMapping.getName(),
method + suffix);
return custom(tempForwardUrl);
}
@Override
public String input() {
return customMethod("add");
}
public String custom(String forwardUrl) {
return _custom(0, forwardUrl);
}
public String customRedirect(String forwardUrl) {
return _custom(2, forwardUrl);
}
public String customRedirectAction(String forwardUrl) {
return _custom(3, forwardUrl);
}
private String _custom(int type, String forwardUrl) {
setForwardUrl(forwardUrl);
return CUSTOM + (type < 1 ? "" : type);
}
public Long getBizId() {
return bizId;
}
public void setBizId(Long bizId) {
this.bizId = bizId;
}
}
0 0
- struts2 零配置代码
- struts2.0 零配置
- Struts2的零配置
- Struts2 零配置注解
- Struts2 零配置注意事项
- Struts2 零配置注解
- Struts2之零配置
- Spring Struts2 零配置
- Struts2-零配置
- STRUTS2 Convention零配置
- struts2零配置-注解
- Struts2注解零配置
- Struts2零配置
- struts2 零配置
- struts2零配置
- Struts2零配置
- Struts2实现零配置
- struts2的零配置
- Java基本类型和取值范围
- ios开发小技巧
- WF4.0和BookMark
- windows多线程同步机制---原子锁
- 浅析计算机接口技术
- struts2 零配置代码
- Excel大小写转换函数
- MD5值 计算_
- 使用JavaScript实现下拉菜单的效果
- Struts2 零配置文件
- Linux操作文件命令
- JZOJ 4224.食物
- POJ2135 最小费用最大流
- 从头认识Spring-2.4 基于java的标准注解装配-@Inject-限定器@Named