本文整理汇总了Java中javax.servlet.jsp.PageContext类的典型用法代码示例。如果您正苦于以下问题:Java PageContext类的具体用法?Java PageContext怎么用?Java PageContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PageContext类属于javax.servlet.jsp包,在下文中一共展示了PageContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getVocabTreeMenu
import javax.servlet.jsp.PageContext; //导入依赖的package包/类
/**
* Generates a Javascript Tree Menu (collapsable hierarchy) of the specified
* part of the vocabulary
*
* @param group colon-seperated specifier of the part of the vocab
* hierarchy which is to be displayed
* @param system
* @param page
* @param language
* @return the Javascript code defining the menu
*/
public synchronized String getVocabTreeMenu( String system,
String language,
String group,
PageContext page ) {
if ( vocabTreeMenuCache.get( system + language + group ) != null ) {
Date now = new Date();
if ( ( now.getTime() - ( (Date)vocabTreeMenuCacheDate.get( system + language + group ) ).getTime() )
< ( VOCAB_TREE_CACHE_TIME ) ) {
return (String)vocabTreeMenuCache.get( system + language + group );
}
}
StringBuffer ret = new StringBuffer();
String inputName = setCurrentTree( system, group );
if ( inputName.startsWith( "ERROR:" ) ) {
return errorDisplay( inputName, "getVocabTreeMenu" );
}
try {
String abbrevLabel = currentNode.getAttribute( "textAbbrev" );
if ( abbrevLabel == null ) {
abbrevLabel = (String)currentNode.getAttribute( "text" );
}
ret.append( "var tm_" + currentNode.fieldId + "0 = new dlese_vocabList( \"tm_" + currentNode.fieldId + "0\", 0, \""
+ currentNode.getAttribute( "text" ) + "\", \"" + abbrevLabel + "\" );\n" );
}
catch ( Exception e ) {
e.printStackTrace();
}
String setList = "\ndlese_setList( \"" + currentNode.fieldId + "\" );\n";
ret.append( vocabTreeMenu( currentNode, currentNode.fieldId + "0", currentNode.fieldId, page ) );
ret.append( setList );
vocabTreeMenuCache.put( system + language + group, ret.toString() );
vocabTreeMenuCacheDate.put( system + language + group, new Date() );
return ret.toString();
}
示例2: JspContextWrapper
import javax.servlet.jsp.PageContext; //导入依赖的package包/类
public JspContextWrapper(JspContext jspContext,
ArrayList<String> nestedVars, ArrayList<String> atBeginVars,
ArrayList<String> atEndVars, Map<String,String> aliases) {
this.invokingJspCtxt = (PageContext) jspContext;
if (jspContext instanceof JspContextWrapper) {
rootJspCtxt = ((JspContextWrapper)jspContext).rootJspCtxt;
}
else {
rootJspCtxt = invokingJspCtxt;
}
this.nestedVars = nestedVars;
this.atBeginVars = atBeginVars;
this.atEndVars = atEndVars;
this.pageAttributes = new HashMap<String, Object>(16);
this.aliases = aliases;
if (nestedVars != null) {
this.originalNestedVars = new HashMap<String, Object>(nestedVars.size());
}
syncBeginTagFile();
}
示例3: message
import javax.servlet.jsp.PageContext; //导入依赖的package包/类
/**
* Look up and return a message string, based on the specified parameters.
*
* @param pageContext The PageContext associated with this request
* @param bundle Name of the servlet context attribute for our
* message resources bundle
* @param locale Name of the session attribute for our user's Locale
* @param key Message key to be looked up and returned
* @param args Replacement parameters for this message
* @return message string
* @exception JspException if a lookup error occurs (will have been
* saved in the request already)
* @deprecated Use {@link org.apache.struts.taglib.TagUtils#message(PageContext,String,String,String,Object[])} instead.
* This will be removed after Struts 1.2.
*/
public static String message(
PageContext pageContext,
String bundle,
String locale,
String key,
Object args[])
throws JspException {
// :TODO: Remove afer Struts 1.2
return TagUtils.getInstance().message(
pageContext,
bundle,
locale,
key,
args);
}
示例4: getPageContext
import javax.servlet.jsp.PageContext; //导入依赖的package包/类
@Override
public PageContext getPageContext(Servlet servlet, ServletRequest request,
ServletResponse response, String errorPageURL, boolean needsSession,
int bufferSize, boolean autoflush) {
if( Constants.IS_SECURITY_ENABLED ) {
PrivilegedGetPageContext dp = new PrivilegedGetPageContext(
this, servlet, request, response, errorPageURL,
needsSession, bufferSize, autoflush);
return AccessController.doPrivileged(dp);
} else {
return internalGetPageContext(servlet, request, response,
errorPageURL, needsSession,
bufferSize, autoflush);
}
}
示例5: setValue
import javax.servlet.jsp.PageContext; //导入依赖的package包/类
@Override
public void setValue(ELContext context, Object base, Object property,
Object value) throws NullPointerException,
PropertyNotFoundException, PropertyNotWritableException,
ELException {
if (context == null) {
throw new NullPointerException();
}
if (base == null) {
context.setPropertyResolved(true);
if (property != null) {
String key = property.toString();
PageContext page = (PageContext) context
.getContext(JspContext.class);
int scope = page.getAttributesScope(key);
if (scope != 0) {
page.setAttribute(key, value, scope);
} else {
page.setAttribute(key, value);
}
}
}
}
示例6: setAttribute
import javax.servlet.jsp.PageContext; //导入依赖的package包/类
/**
* Store bean in requested context.
* If scope is <code>null</code>, save it in REQUEST_SCOPE context.
*
* @param pageContext Current pageContext.
* @param name Name of the bean.
* @param scope Scope under which bean is saved (page, request, session, application)
* or <code>null</code> to store in <code>request()</code> instead.
* @param value Bean value to store.
*
* @exception JspException Scope name is not recognized as a valid scope
*/
public static void setAttribute(
PageContext pageContext,
String name,
Object value,
String scope)
throws JspException {
if (scope == null)
pageContext.setAttribute(name, value, PageContext.REQUEST_SCOPE);
else if (scope.equalsIgnoreCase("page"))
pageContext.setAttribute(name, value, PageContext.PAGE_SCOPE);
else if (scope.equalsIgnoreCase("request"))
pageContext.setAttribute(name, value, PageContext.REQUEST_SCOPE);
else if (scope.equalsIgnoreCase("session"))
pageContext.setAttribute(name, value, PageContext.SESSION_SCOPE);
else if (scope.equalsIgnoreCase("application"))
pageContext.setAttribute(name, value, PageContext.APPLICATION_SCOPE);
else {
throw new JspException("Error - bad scope name '" + scope + "'");
}
}
示例7: getFileText
import javax.servlet.jsp.PageContext; //导入依赖的package包/类
/**
* Reads the given file and returns its contents as a string
*
* @param filename
* @param page
* @return The fileText value
*/
private synchronized String getFileText( String filename, PageContext page ) {
StringBuffer ret = new StringBuffer();
try {
BufferedReader in = new BufferedReader( new FileReader( page.getServletContext().getRealPath( filename ) ) );
String s = null;
while ( ( s = in.readLine() ) != null ) {
ret.append( s );
}
}
catch ( FileNotFoundException fnfe ) {
System.err.println( "File not found - " );
System.err.println( fnfe.getClass() + " " + fnfe.getMessage() );
}
catch ( IOException ioe ) {
System.err.println( "Exception occurred reading " + filename );
System.err.println( ioe.getClass() + " " + ioe.getMessage() );
}
return ret.toString();
}
示例8: getResponseOPML
import javax.servlet.jsp.PageContext; //导入依赖的package包/类
/**
* Gets the re-ordered/grouped/labeled OPML tree of metadata values from the
* cache created by setResponseGroup()
*
* @param context JSP page context
* @return OPML for the group specified with setResponseGroup() and
* trimmed to the subset indicated by values passed into setResponse()
* @see MetadataVocab#setResponseValue(String,PageContext)
* @see MetadataVocab#setResponseList(String[],PageContext)
* @see MetadataVocab#setResponseList(ArrayList,PageContext)
* @see MetadataVocab#setResponseGroup(PageContext,String,String,String,String,String)
*/
public synchronized String getResponseOPML( PageContext context ) {
String ret = "";
MetadataVocabResponseMap responseMap = (MetadataVocabResponseMap)context.findAttribute( "metadataVocabResponseMap" );
if ( responseMap == null ) {
ret = "<!-- MUI ERROR: metadataVocabResponseMap is empty -->";
}
if ( ( responseMap.metaVersion == null ) || responseMap.metaVersion.equals( "" ) ) {
ret = getOPML( responseMap.metaFormat, getCurrentVersion( responseMap.metaFormat ),
responseMap.audience, responseMap.language, responseMap.field, responseMap, false );
}
else {
ret = getOPML( responseMap.metaFormat, responseMap.metaVersion,
responseMap.audience, responseMap.language, responseMap.field, responseMap, false );
}
if ( ret.indexOf( "<outline" ) == -1 ) {
ret = "";
}
return ret;
}
示例9: getHtmlIdPrefix
import javax.servlet.jsp.PageContext; //导入依赖的package包/类
/** Get the HTML id for the form. This is based on the application rule
* "jaffa.widgets.form.idFormat" which can have the following values
* <ul>
* <li>none - No id will be used for the form
* <li>formname - The struts form name will be used
* <li>index - an index value, based on the number of forms on the page will be used.
* The value will be prefixed with 'j', so the first form will be id='j0'
* <li>class - Will used the classname of the formbean (without the package name) for the id
* </ul>
* Older version of JAFFA used the equivilent of 'formname' which is the default if nothing is set.
*/
public String getHtmlIdPrefix() {
if(m_htmlName!=null) {
m_htmlIdPrefix=m_htmlName;
} else if(m_htmlIdPrefix==null) {
if(ID_FORMAT_INDEX.equals(m_idFormat)) {
//Look for a index counter in the request
Integer index = (Integer)pageContext.getAttribute(FORM_TAG_INDEX,PageContext.REQUEST_SCOPE);
if(index==null)
index=new Integer(1);
m_htmlIdPrefix="j" + index;
pageContext.setAttribute(FORM_TAG_INDEX,new Integer(index.intValue()+1),PageContext.REQUEST_SCOPE);
} else if(ID_FORMAT_NONE.equals(m_idFormat))
// use no id
m_htmlIdPrefix="";
else if(ID_FORMAT_CLASS.equals(m_idFormat)) {
// Use the class name (exclude the package)
m_htmlIdPrefix=StringHelper.getShortClassName(FormTag.class);
} else {
// Default to original behavior, and use the struts Bean name
m_htmlIdPrefix=getBeanName();
}
}
return m_htmlIdPrefix;
}
示例10: setupTag
import javax.servlet.jsp.PageContext; //导入依赖的package包/类
/**
* Get the vocab object from the page context and expand system to be a
* concatenation of system, interface, and language
*
* @param pageContext
* @exception JspException
*/
public void setupTag( PageContext pageContext ) throws JspException {
String contextAttributeName = (String)pageContext.getServletContext().getInitParameter( "metadataVocabInstanceAttributeName" );
vocab = (MetadataVocab)pageContext.findAttribute( contextAttributeName );
if ( vocab == null ) {
System.out.println( "Looked for vocab in " + contextAttributeName );
throw new JspException( "Vocabulary not found" );
}
else {
try {
metaVersion = vocab.getCurrentVersion( metaFormat );
}
catch ( Exception e ) {
new JspException( "No current version found for metadata framework " + metaFormat );
}
system = metaFormat + "/" + metaVersion + "/" + audience + "/" + language + "/" + field;
( (MetadataVocabOPML)vocab ).setCurrentTree( system, subGroup );
}
}
示例11: setupTag
import javax.servlet.jsp.PageContext; //导入依赖的package包/类
/**
* Get the vocab object from the page context and expand system to be a
* concatenation of system, interface, and language
*
* @param pageContext
* @exception JspException
*/
public void setupTag( PageContext pageContext ) throws JspException {
vocab = (MetadataVocab)pageContext.findAttribute( "MetadataVocab" );
if ( vocab == null ) {
throw new JspException( "Vocabulary not found" );
}
else {
if ( group != null ) {
group = stringUtil.replace( group, " ", "_", false );
}
else {
group = "";
}
system = system + "." + interfce + "." + language;
}
}
示例12: doEndTag
import javax.servlet.jsp.PageContext; //导入依赖的package包/类
public int doEndTag() throws JspException {
// Rewrite and encode the url.
String result = formatUrl();
// Store or print the output
if (var != null)
pageContext.setAttribute(var, result, PageContext.PAGE_SCOPE);
else {
try {
pageContext.getOut().print(result);
} catch (IOException x) {
throw new JspTagException(x);
}
}
return EVAL_PAGE;
}
示例13: setValue
import javax.servlet.jsp.PageContext; //导入依赖的package包/类
@Override
public void setValue(ELContext context, Object base, Object property, Object value)
throws NullPointerException, PropertyNotFoundException, PropertyNotWritableException, ELException {
if (context == null) {
throw new NullPointerException();
}
if (base == null) {
context.setPropertyResolved(true);
if (property != null) {
String key = property.toString();
PageContext page = (PageContext) context.getContext(JspContext.class);
int scope = page.getAttributesScope(key);
if (scope != 0) {
page.setAttribute(key, value, scope);
} else {
page.setAttribute(key, value);
}
}
}
}
示例14: getScope
import javax.servlet.jsp.PageContext; //导入依赖的package包/类
/**
* Determines the scope for a given input {@code String}.
* <p>If the {@code String} does not match 'request', 'session',
* 'page' or 'application', the method will return {@link PageContext#PAGE_SCOPE}.
* @param scope the {@code String} to inspect
* @return the scope found, or {@link PageContext#PAGE_SCOPE} if no scope matched
* @throws IllegalArgumentException if the supplied {@code scope} is {@code null}
*/
public static int getScope(String scope) {
Assert.notNull(scope, "Scope to search for cannot be null");
if (scope.equals(SCOPE_REQUEST)) {
return PageContext.REQUEST_SCOPE;
}
else if (scope.equals(SCOPE_SESSION)) {
return PageContext.SESSION_SCOPE;
}
else if (scope.equals(SCOPE_APPLICATION)) {
return PageContext.APPLICATION_SCOPE;
}
else {
return PageContext.PAGE_SCOPE;
}
}
示例15: initialize
import javax.servlet.jsp.PageContext; //导入依赖的package包/类
public final void initialize(PageContext pagecontext)
throws ServletException
{
m_application = pagecontext.getServletContext();
m_request = (HttpServletRequest)pagecontext.getRequest();
m_response = (HttpServletResponse)pagecontext.getResponse();
}