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

📄 jsp.java

📁 webwork source
💻 JAVA
字号:
/* * WebWork, Web Application Framework * * Distributable under Apache license. * See terms of license at opensource.org */package webwork.action.standard;import webwork.action.Action;import webwork.action.ActionSupport;import webwork.action.ActionContext;import webwork.action.factory.ActionFactory;import javax.servlet.RequestDispatcher;import javax.servlet.ServletOutputStream;import javax.servlet.http.Cookie;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpServletResponseWrapper;import java.io.IOException;import java.io.PrintWriter;import java.io.StringWriter;import java.util.Locale;import org.apache.commons.logging.*;/** *	JSP execution wrapper. This action allows JSP pages to be executed as actions. * * The JSP page should set the request attribute "result" to the result status. * Well defined result status constants are defined in the Action interface. * *	@see webwork.action.Action *	@author Rickard 謆erg (rickard@middleware-company.com) *	@version $Revision: 1.10 $ */public class JSP   extends ActionSupport{   // Static --------------------------------------------------------   // Attributes ----------------------------------------------------   String pageName;   RequestDispatcher dispatcher;   /**    * Get name of the page that is wrapped    */   public String getPage()   {      return pageName;   }   /**    * Set the name of the page that is to be executed.    *    * @see webwork.action.factory.JspActionFactoryProxy    */   public void setPage(String aPageName)   {      pageName = aPageName;      dispatcher = ActionContext.getContext().getRequest().getRequestDispatcher(aPageName);   }   // Action implementation -----------------------------------------   /**    * Execute the wrapper. This will forward to the given JSP-page,    * which then can execute arbitrary code (possibly using tag libraries).    * The JSP page should then set the "result" request attribute to the    * result state of the execution.    *    * Any content generated by the JSP page will be thrown away.    */   public String execute()      throws Exception   {      // Get servlet context      ActionContext ctx = ActionContext.getContext();      // Create wrapper which ignores all content-modifying calls      HttpServletResponse res = new WrapperHttpServletResponse(ctx.getResponse());      String oldResult = (String)ctx.getRequest().getAttribute("result");      // Execute JSP      dispatcher.forward(ctx.getRequest(), res);      // Extract the result      String result =(String)ctx.getRequest().getAttribute("result");      // Default to success      if (result == null)         result = Action.SUCCESS;      // Restore request attribute      if (oldResult == null)         ctx.getRequest().removeAttribute("result");      else         ctx.getRequest().setAttribute("result", oldResult);      return result;   }   // Public --------------------------------------------------------   // Protected -----------------------------------------------------   // Inner classes -------------------------------------------------   /**    * Response wrapper. Delegate to real response, but    * ignore all content modifying calls and return    * dummies instead of real streams.    */   public class WrapperHttpServletResponse      extends HttpServletResponseWrapper   {      WrapperHttpServletResponse(HttpServletResponse aResponse)      {         super(aResponse);      }      public void flushBuffer() throws IOException      {         // Ignore      }      public ServletOutputStream getOutputStream() throws IOException      {         return new ServletOutputStream()         {            public void write(int b) throws IOException            {               // Throw away            }         };      }      public PrintWriter getWriter() throws IOException      {         return new PrintWriter(new StringWriter());      }      public void resetBuffer()      {         //response.resetBuffer();      }      public void setContentType(String s)      {         // Ignore      }   }}

⌨️ 快捷键说明

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