📄 pi3pagecontext.java
字号:
* and application scope(s) in order and returns the value associated or
* null.
* </p>
*
* @return the value associated or null
*/
public Object findAttribute(String name) {
Object o = attr.get(name);
if (o != null) return o;
o = req.getAttribute(name);
if (o != null) return o;
o = (getSession() != null) ? getSession().getValue(name) : null;
if (o != null) return o;
return getServletContext().getAttribute(name);
};
/**
* remove the object reference associated with the specified name
*/
public void removeAttribute(String name) {
attr.remove(name);
};
/**
* remove the object reference associated with the specified name
*/
public void removeAttribute(String name, int scope) {
switch (scope) {
case 1 /* PAGE_SCOPE */ :
attr.remove(name); break;
case 2 /* REQUEST_SCOPE */ :
((Pi3HttpServletRequest)req).removeAttribute(name); break;
case 3 /* SESSION_SCOPE */ :
if (getSession() != null) getSession().removeValue(name); break;
case 4 /* APPLICATION_SCOPE */ :
getServletContext().removeAttribute(name); break;
default: throw new IllegalArgumentException("Invalid scope.");
};
};
/**
* @return the scope of the object associated with the name specified or 0
*/
public int getAttributesScope(String name) {
if (attr.get(name) != null) return PageContext.PAGE_SCOPE;
if (req.getAttribute(name) != null) return PageContext.REQUEST_SCOPE;
if ((getSession() != null) && (getSession().getValue(name) != null)) return PageContext.SESSION_SCOPE;
if (getServletContext().getAttribute(name) != null) return PageContext.APPLICATION_SCOPE;
return 0;
};
/**
* @return an enumeration of names (java.lang.String) of all the attributes the specified scope
*/
public Enumeration getAttributeNamesInScope(int scope) {
switch (scope) {
case 1 /* PAGE_SCOPE */ :
return attr.keys();
case 2 /* REQUEST_SCOPE */ :
return ((Pi3HttpServletRequest)req).getAttributeNames();
case 3 /* SESSION_SCOPE */ :
/* This is what you can do with Servlet API 2.1 */
/* if (getSession() != null) {
String [] names = getSession().getValueNames();
Vector v = new Vector();
for (int i = 0; i < Array.getLength(names);) v.add(names[i++]);
return v.elements();
} else {
return new Vector().elements();
};
*/
if (getSession() != null) {
return ((Pi3HttpSession)getSession()).getPi3ValueNames();
} else {
return new Vector().elements();
};
case 4 /* APPLICATION_SCOPE */ :
return getServletContext().getAttributeNames();
default: throw new IllegalArgumentException("Invalid scope.");
};
};
/**
* @return the current JspWriter stream being used for client response
*/
public JspWriter getOut() { return out; }
/**
* @return the HttpSession for this PageContext or null
*/
public HttpSession getSession() {
return nSess ? ((HttpServletRequest)req).getSession(true) : null;
}
/**
* @return the Page implementation class instance (Servlet) associated with this PageContext
*/
public Object getPage() { return srl; }
/**
* @return The ServletRequest for this PageContext
*/
public ServletRequest getRequest() { return req; }
/**
* @return the ServletResponse for this PageContext
*/
public ServletResponse getResponse() { return res; }
/**
* @return any exception passed to this as an errorpage
*/
public Exception getException() {
return (Exception)getRequest().getAttribute("javax.servlet.jsp.jspException");
};
/**
* @return the ServletConfig for this PageContext
*/
public ServletConfig getServletConfig() { return srl.getServletConfig(); };
/**
* @return the ServletContext for this PageContext
*/
public ServletContext getServletContext() { return srl.getServletConfig().getServletContext(); };
/**
* <p>
* This method is used to re-direct, or "forward" the current ServletRequest and
* ServletResponse to another active component in the application.
* </p>
* <p>
* If the <I> relativeUrlPath </I> begins with a "/" then the URL specified
* is calculated relative to the DOCROOT of the <code> ServletContext </code>
* for this JSP. If the path does not begin with a "/" then the URL
* specified is calculated relative to the URL of the request that was
* mapped to the calling JSP.
* </p>
* <p>
* It is only valid to call this method from a <code> Thread </code>
* executing within a <code> _jspService(...) </code> method of a JSP.
* </p>
* <p>
* Once this method has been called successfully, it is illegal for the
* calling <code> Thread </code> to attempt to modify the <code>
* ServletResponse </code> object. Any such attempt to do so, shall result
* in undefined behavior. Typically, callers immediately return from
* <code> _jspService(...) </code> after calling this method.
* </p>
*
* @param relativeUrlPath specifies the relative URL path to the target resource as described above
*
* @throws ServletException
* @throws IOException
*
* @throws IllegalArgumentException if target resource URL is unresolvable
* @throws IllegalStateException if <code> ServletResponse </code> is not in a state where a forward can be performed
* @throws SecurityException if target resource cannot be accessed by caller
*/
public void forward(String relativeUrlPath) throws ServletException, IOException {
RequestDispatcher dsp = getServletContext().getRequestDispatcher(relativeUrlPath);
if (dsp != null) {
dsp.forward(req, res);
} else {
throw new IllegalArgumentException("Target resource URL is unresolvable.");
};
};
/**
* <p>
* Causes the resource specified to be processed as part of the current
* ServletRequest and ServletResponse being processed by the calling Thread.
* The output of the target resources processing of the request is written
* directly to the ServletResponse output stream.
* </p>
* <p>
* The current JspWriter "out" for this JSP is flushed as a side-effect
* of this call, prior to processing the include.
* </p>
* <p>
* If the <I> relativeUrlPath </I> begins with a "/" then the URL specified
* is calculated relative to the DOCROOT of the <code> ServletContext </code>
* for this JSP. If the path does not begin with a "/" then the URL
* specified is calculated relative to the URL of the request that was
* mapped to the calling JSP.
* </p>
* <p>
* It is only valid to call this method from a <code> Thread </code>
* executing within a <code> _jspService(...) </code> method of a JSP.
* </p>
*
* @param relativeUrlPath specifies the relative URL path to the target resource to be included
*
* @throws ServletException
* @throws IOException
*
* @throws IllegalArgumentException if the target resource URL is unresolvable
* @throws SecurityException if target resource cannot be accessed by caller
*
*/
public void include(String relativeUrlPath) throws ServletException, IOException {
RequestDispatcher dsp = getServletContext().getRequestDispatcher(relativeUrlPath);
if (dsp != null) {
dsp.include(req, res);
} else {
throw new IllegalArgumentException("Target resource URL is unresolvable.");
};
};
/**
* <p>
* This method is intended to process an unhandled "page" level exception
* by redirecting the exception to either the specified error page for this
* JSP, or if none was specified, to perform some implementation dependent
* action.
* </p>
* <p>
* A JSP implementation class shall typically clean up any local state
* prior to invoking this and will return immediately thereafter. It is
* illegal to generate any output to the client, or to modify any
* ServletResponse state after invoking this call.
* </p>
*
* @param e the exception to be handled
*
* @throws ServletException
* @throws IOException
*
* @throws NullPointerException if the exception is null
* @throws SecurityException if target resource cannot be accessed by caller
*/
public void handlePageException(Exception e) throws ServletException, IOException {
if (errPage != null) forward(errPage);
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -