📄 forward.java
字号:
package com.exp.web.util.navigation;
import com.exp.fcl.security.EventLog;
import com.exp.fcl.security.UserLogin;
import com.exp.fcl.syscfg.SystemConfig;
import com.exp.fcl.util.StringUtil;
import com.exp.web.util.FormBean;
import com.exp.web.util.PageWrapper;
public class Forward {
private static String PARAM_SIGN = "$";
public static final String DYNMIC_FLAG = "dyn:";
private boolean isDynmic = false;
private String subject = "";
private boolean bForward = false;
private String url;
public Forward(String subject, String forwardUrl, String forward) {
if (null != subject) {
this.subject = subject;
}
this.url = forwardUrl;
if ("true".equalsIgnoreCase(forward)) {
bForward = true;
}
}
public Forward(String forwardUrl) {
this("dynmic forward", forwardUrl, "false");
this.isDynmic = true;
}
public String getSubject() {
return this.subject;
}
public void doForward(PageWrapper pageWrapper) throws Exception {
if (!"".equals(this.url)) {
String target = replaceParams(this.url, pageWrapper.FormBean);
logForward(pageWrapper, target);
if (SystemConfig.ForwardEnCoding) {
target = StringUtil.deCoding(target);
}
if (target.startsWith("/")) {
target = pageWrapper.request.getContextPath() + target;
}
if (target.toLowerCase().startsWith("http://")
|| target.toLowerCase().startsWith("https://")) {
pageWrapper.response.sendRedirect(target);
} else {
if (this.bForward) {
pageWrapper.pageContext.forward(target);
} else {
pageWrapper.response.sendRedirect(target);
}
}
}
}
/**
* 记录导航日志
*
* @param pageContext
* 页面上下文
* @param toUri
* 待导航的链接
*/
protected static void logForward(PageWrapper pageContext, String toUri) {
String sourceUri = pageContext.request.getRequestURI();
EventLog log = EventLog.getDebugLog();
if (log.isLogEnabled()) {
StringBuffer buf = new StringBuffer();
UserLogin login = pageContext.login;
buf.append("[导航记录]");
if (login != null) {
buf.append("用户");
buf.append(login.getUserID());
}
buf.append("从");
buf.append(sourceUri);
buf.append("到");
buf.append(toUri);
log.log(buf);
}
}
/**
* 处理导航链接中的参数
*
* @param value
* 导航链接
* @param formBean
* 当前FormBean
* @return 处理后的链接
*/
public static String replaceParams(String value, FormBean formBean) {
String ret = value;
String param = StringUtil.findFirstParam(PARAM_SIGN, PARAM_SIGN, ret);
while (!param.equals("")) {
String paramValue = formBean.getString(param);
if (SystemConfig.ParamEnCoding) {
paramValue = StringUtil.URLEncoding(paramValue);
}
ret = ret.replaceFirst("\\" + PARAM_SIGN + param + "\\"
+ PARAM_SIGN, paramValue);
param = StringUtil.findFirstParam(PARAM_SIGN, PARAM_SIGN, ret);
}
return ret;
}
public boolean equals(Object parm1) {
return this.subject.equals(parm1);
}
public String toString() {
if (this.isDynmic) {
return DYNMIC_FLAG + this.url;
}
return this.subject;
}
public int hashCode() {
return this.subject.hashCode();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -