是否能够在Action里直接return /WEB-INF/jsp/xxx.jsp 或是 xxx
而不是返回return SUCCESS 这些struts配置文件里定义的用request和reponse
请求转发:
request.getRequestDispatcher("target.jsp").forward(request.response);
重定向:
response.sendRedirect("target.jsp");
/**
* 用户员工action
* @version 1.0
*/
@ActionBean(name = "/user", interceptor = "myInterceptor")
public class UserAction extends BaseAction {
private static final Logger log = LoggerFactory.getLogger(UserAction.class);
private static final String LIST = "/jsp/user/list.jsp";
private static final String ADD = "/jsp/user/add.jsp";
private static final String EDIT = "/jsp/user/edit.jsp";
private static final String PROMPT = "/prompt.jsp";
/**
* 员工列表
* @return String
*/
public String list() {
log.info("员工列表");
return LIST;
}
/**
* 添加员工
* @return String
*/
public String add() {
if ("save".equals(paramString(METHOD_NAME))) {
try {
Company company = companyMng.get(id);
bean.setCompany(company);
bean.setNamePY(UtilTool.getBean().getFirstPinyin(bean.getRealName()));
bean = mng.add(bean);
company.setUserNum(company.getUserNum() + 1);
company = companyMng.edit(company);
resetPage(OPERATE_RIGHT, "parent.getUsers();", "添加员工【" + bean.getRealName() + "】成功!");
} catch (Exception e) {
resetPage(OPERATE_ERROR, "", OPERATE_ERROR_MESSAGE);
}
return PROMPT;
}
setRequestAttr("company", companyMng.get(id));
return ADD;
}
/**
* 编辑员工
* @return String
*/
public String edit() {
if ("update".equals(paramString(METHOD_NAME))) {
try {
bean.setNamePY(UtilTool.getBean().getFirstPinyin(bean.getRealName()));
bean = mng.edit(bean);
resetPage(OPERATE_RIGHT, "parent.getUsers();", "编辑员工【" + bean.getRealName() + "】成功!");
} catch (Exception e) {
resetPage(OPERATE_ERROR, "", OPERATE_ERROR_MESSAGE);
}
return PROMPT;
}
bean = mng.get(id);
return EDIT;
}
/**
* 删除员工
* @return String
*/
public String del() {
try {
bean = mng.del(id);
Company company = bean.getCompany();
company.setUserNum(company.getUserNum() - 1);
company = companyMng.edit(company);
resetPage(OPERATE_RIGHT, "parent.getUsers();", "删除员工【" + bean.getRealName() + "】成功!");直接在Action 实现ServletRequestAware、ServletResponseAware接口 重写方法;并获得request或者是response;
利用request.getRequestDispatcher("XXXX.jsp").forward(request.response);
或者response.sendRedirect("xxxx.jsp");
但是不推荐这样做~~,这样破坏了struts2的思想