⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resultdispatcher.java

📁 本源码为教学管理信息系统
💻 JAVA
字号:
package com.hibernate.action;import javax.servlet.RequestDispatcher;import javax.servlet.http.Cookie;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.jsp.PageContext;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import com.opensymphony.webwork.ServletActionContext;import com.opensymphony.webwork.dispatcher.ServletDispatcherResult;import com.opensymphony.webwork.dispatcher.WebWorkResultSupport;import com.opensymphony.xwork.ActionContext;import com.opensymphony.xwork.ActionInvocation;import com.opensymphony.xwork.util.OgnlValueStack;/** * @author Administrator 带导航的请求分发 */public class ResultDispatcher extends WebWorkResultSupport {	private static final Log log = LogFactory			.getLog(ServletDispatcherResult.class);	public void doExecute(String finalLocation, ActionInvocation invocation)			throws Exception {		if (log.isDebugEnabled()) {			log.debug("Forwarding to location " + finalLocation);		}		PageContext pageContext = ServletActionContext.getPageContext();		if (pageContext != null) {			pageContext.include(finalLocation);		} else {			HttpServletRequest request = ServletActionContext.getRequest();			HttpServletResponse response = ServletActionContext.getResponse();			RequestDispatcher dispatcher = request					.getRequestDispatcher(finalLocation);			// if the view doesn't exist, let's do a 404			if (dispatcher == null) {				response.sendError(404, "result '" + finalLocation						+ "' not found");				return;			}			String isPortal = (String) ActionContext.getContext().getSession()					.get("IsPortal");			if(isPortal != null){				if (isPortal.equals("1")) {					} else {					OgnlValueStack stack = ActionContext.getContext()							.getValueStack();					String navigation = (String) stack.findValue("navigation");					StringBuffer sb = new StringBuffer();					sb.append("<br><center>");					sb.append("<table width=\"90%\" border=0>");					sb.append("<tr>");					sb.append("<td align=left bgcolor=\"#EEEEEE\">" + navigation							+ "</td>");					sb.append("</tr>");					sb.append("</table>");					sb.append("<br>");					sb.append(GetStyleCookie(request, response).toString());					request.setAttribute("navigation", sb);				}			}			// If we're included, then include the view			// Otherwise do forward			// This allow the page to, for example, set content type			if (!response.isCommitted()					&& (request							.getAttribute("javax.servlet.include.servlet_path") == null)) {				request.setAttribute("webwork.view_uri", finalLocation);				request.setAttribute("webwork.request_uri", request						.getRequestURI());				dispatcher.forward(request, response);			} else {				dispatcher.include(request, response);			}		}	}	private StringBuffer GetStyleCookie(HttpServletRequest request,HttpServletResponse response) {		StringBuffer style = new StringBuffer();		try {			Cookie cookies[] = request.getCookies();			Cookie Cookie = null;			String CookieName = null;			String CookieValue = "Default";			if (cookies == null) {				Cookie _cookie = new Cookie("UserStyle", "Default");				_cookie.setMaxAge(0x1e13380);				response.addCookie(_cookie);			} else {				for (int i = 0; i < cookies.length; i++) {					Cookie = cookies[i];					CookieName = Cookie.getName();					if (CookieName.equals("UserStyle"))						CookieValue = Cookie.getValue();				}			}						style.append("<link rel=\"stylesheet\" href=\"/css/" + CookieValue + ".css\">");			style.append("<link rel=\"stylesheet\" href=\"/css/Others.css\">");		} catch (Exception e) {			e.printStackTrace();			style.append("<link rel=\"stylesheet\" href=\"/css/Default.css\">");			style.append("<link rel=\"stylesheet\" href=\"/css/Others.css\">");					}		return style;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -