Java javax.servlet.jsp.PageContext 代码实例

作者:无名 - 开发 -

以下是展示如何使用javax.servlet.jsp.pagecontext的最佳示例。 我们使用了代码质量辨别算法从开源项目中提取出了最佳的优秀示例。

实例 1


public void testmessagesessionbadkey() {

putbundleinscope(pagecontext.session_scope, true);

string val = null;

try {

val = tagutils.message(pagecontext, null, null,

"foo.bar.does.not.exist");

fail("messageresources should never be put in session scope.");

} catch (jspexception e) {

assertnull(val);

}

}

实例 2


public void dotag() throws jspexception, ioexception {

classlt;gt; resolvingclass = (classlt;gt;)getjspcontext().getattribute("resolvingclass", pagecontext.request_scope);

final classlt;gt; oldresolvingclass = resolvingclass;

if (this.resolvingclass != null) {

resolvingclass = this.resolvingclass;

}

servletconfig cfg = (servletconfig) getpageobject(pagecontext.config);

servletcontext sc = cfg.getservletcontext();

string basepath = (string)getjspcontext().getattribute("_basepath", pagecontext.request_scope);

for (class c = resolvingclass; c != object.class; c = c.getsuperclass()) {

string name = basepath + "/" + c.getname().replace('.', '/') + '/' + page;

if (sc.getresource(name) != null) {

// tomcat returns a requestdispatcher even if the jsp file doesn't exist.

// so check if the resource exists first.

requestdispatcher disp = sc.getrequestdispatcher(name);

if (disp != null) {

getjspcontext().setattribute("resolvingclass", resolvingclass, pagecontext.request_scope);

try {

httpservletrequest request = (httpservletrequest) getpageobject(pagecontext.request);

disp.include(

request,

new wrapper(

(httpservletresponse) getpageobject(pagecontext.response),

new printwriter(getjspcontext().getout())));

} catch (servletexception e) {

throw new jspexception(e);

} finally {

getjspcontext().setattribute("resolvingclass", oldresolvingclass, pagecontext.request_scope);

}

return;

}

}

}

throw new jspexception("unable to find '" + page + "' for " + resolvingclass);

}

实例 3


public void testmessageapplicationbadkey() {

putbundleinscope(pagecontext.application_scope, true);

string val = null;

try {

val = tagutils.message(pagecontext, null, null,

"foo.bar.does.not.exist");

assertnull(val);

} catch (jspexception e) {

fail("val should be null, no exception");

}

}

实例 4


/**

* store bean in requested context.

* if scope is lt;codegt;nulllt;/codegt;, 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 lt;codegt;nulllt;/codegt; to store in lt;codegt;request()lt;/codegt; 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 + "'");

}

}

实例 5


public static void setresponselocale(pagecontext pagecontext, locale locale)

throws jspexception

{

servletresponse response = pagecontext.getresponse();

response.setlocale(locale);

httpsession session = pagecontext.getsession();

if (session != null)

coresettag.setvalue(pagecontext,

"javax.servlet.jsp.jstl.fmt.request.charset",

"session",

response.getcharacterencoding());

}

实例 6


/**

* write the specified text as the response to the writer associated with

* this page.lt;stronggt;warninglt;/stronggt; - if you are writing body content

* from the lt;codegt;doafterbody()lt;/codegt; method of a custom tag class that

* implements lt;codegt;bodytaglt;/codegt;, you should be calling

* lt;codegt;writeprevious()lt;/codegt; instead.

*

* @param pagecontext the pagecontext object for this page

* @param textthe text to be written

* @throws jspexception if an input/output error occurs (already saved)

*/

public void write(pagecontext pagecontext, string text)

throws jspexception {

jspwriter writer = pagecontext.getout();

try {

writer.print(text);

} catch (ioexception e) {

saveexception(pagecontext, e);

throw new jspexception(messages.getmessage("write.io", e.tostring()), e);

}

}

实例 7


@override

public iteratorlt;featuredescriptorgt;

getfeaturedescriptors(elcontext context, object base)

{

if (base != null)

return null;

pagecontext pagecontext

= (pagecontext) context.getcontext(jspcontext.class);

context.setpropertyresolved(true);

arraylistlt;featuredescriptorgt; keys = new arraylistlt;featuredescriptorgt;();

enumeration e = pagecontext.getattributenamesinscope(pagecontext.page_scope);

while (e.hasmoreelements()) {

object key = e.nextelement();

string name = (string) key;

featuredescriptor desc = new featuredescriptor();

desc.setname(name);

desc.setdisplayname(name);

desc.setshortdescription("");

desc.setexpert(false);

desc.sethidden(false);

desc.setpreferred(true);

if (key == null)

desc.setvalue(elresolver.type, null);

else

desc.setvalue(elresolver.type, key.getclass());

desc.setvalue(elresolver.resolvable_at_design_time, boolean.true);

keys.add(desc);

}

return keys.iterator();

}

实例 8


@suppresswarnings("unchecked")

public static valueexpression createvalueexpression(string paramstring,

class paramclass, pagecontext parampagecontext,

functionmapper paramfunctionmapper) {

expressionfactory localexpressionfactory = getexpressionfactory(parampagecontext);

elcontext localelcontextimpl = parampagecontext

.getelcontext();

return localexpressionfactory.createvalueexpression(localelcontextimpl,

paramstring, paramclass);

}

实例 9


@override public void dotag() throws jspexception, ioexception {

super.dotag();

pagecontext pagecontext = (pagecontext) this.getjspcontext();

servletcontext servletcontext = pagecontext.getservletcontext();

webapplicationcontext wac = webapplicationcontextutils.getrequiredwebapplicationcontext(servletcontext);

isettschemeservice settschemeservice = wac.getbean("settschemeservice", isettschemeservice.class);

string schemename = "";

settschemedo settschemedo = settschemeservice.getbyschemeid(paymentmodeid);

if (settschemedo!=null amp;amp; stringutils.isnotblank(settschemedo.getschemename())){

schemename = settschemedo.getschemename();

}

getjspcontext().getout().write(schemename);

}

实例 10


public static void setvalue(pagecontext pagecontext,

string var, string scope, object value)

throws jspexception

{

if (var == null) {

if (scope != null amp;amp; ! "".equals(scope))

throw new jspexception(l.l("var must not be null when scope '{0}' is set.",

scope));

}

else if ("".equals(var)) {

throw new jspexception(l.l("var must not be ''"));

}

else if (scope == null || scope.equals("page")) {

if (value != null)

pagecontext.setattribute(var, value);

else

pagecontext.removeattribute(var);

}

else if (scope.equals("request")) {

if (value != null)

pagecontext.getrequest().setattribute(var, value);

else

pagecontext.getrequest().removeattribute(var);

}

else if (scope.equals("session")) {

if (value != null)

pagecontext.getsession().setattribute(var, value);

else

pagecontext.getsession().removeattribute(var);

}

else if (scope.equals("application")) {

if (value != null)

pagecontext.getservletcontext().setattribute(var, value);

else

pagecontext.getservletcontext().removeattribute(var);

}

else

throw new jspexception(l.l("illegal scope value {0}", scope));

}

实例 11


public void freepagecontext(pagecontext pc)

{

if (pc != null) {

pc.release();

if (pc instanceof pagecontextimpl)

_freepages.free((pagecontextimpl) pc);

}

}

实例 12


/**

* return the form action converted into a server-relative url.

*/

public string getactionmappingurl(string action, string module,

pagecontext pagecontext, boolean contextrelative) {

httpservletrequest request =

(httpservletrequest) pagecontext.getrequest();

string contextpath = request.getcontextpath();

stringbuffer value = new stringbuffer();

// avoid setting two slashes at the beginning of an action:

//the length of contextpath should be more than 1

//in case of non-root context, otherwise length==1 (the slash)

if (contextpath.length() gt; 1) {

value.append(contextpath);

}

moduleconfig moduleconfig = getmoduleconfig(module, pagecontext);

if ((moduleconfig != null) amp;amp; (!contextrelative)) {

value.append(moduleconfig.getprefix());

}

// use our servlet mapping, if one is specified

string servletmapping =

(string) pagecontext.getattribute(globals.servlet_key,

pagecontext.application_scope);

if (servletmapping != null) {

string querystring = null;

int question = action.indexof("");

if (question gt;= 0) {

querystring = action.substring(question);

}

string actionmapping = getactionmappingname(action);

if (servletmapping.startswith("*.")) {

value.append(actionmapping);

value.append(servletmapping.substring(1));

} else if (servletmapping.endswith("/*")) {

value.append(servletmapping.substring(0,

servletmapping.length() - 2));

value.append(actionmapping);

} else if (servletmapping.equals("/")) {

value.append(actionmapping);

}

if (querystring != null) {

value.append(querystring);

}

}

// otherwise, assume extension mapping is in use and extension is

// already included in the action property

else {

if (!action.startswith("/")) {

value.append("/");

}

value.append(action);

}

return value.tostring();

}



IT人知识库 该篇知识地址:http://www.itpeo.net/389615/4587069.html





标签 代码实例

Java org.robolectric.Robolectric 代码实例

以下是展示如何使用org.robolectric.robolectric的最佳示例。 我们使用了代码质量辨别算法从开源项 ...

Java net.minecraft.client.gui.inventory.GuiContainer 代码实例

以下是展示如何使用net.minecraft.client.gui.inventory.guicontainer的最佳示 ...

Java javax.annotation.processing.ProcessingEnvironment 代码实例

以下是展示如何使用javax.annotation.processing.processingenvironment的最 ...

Java com.fasterxml.jackson.core.JsonToken 代码实例

以下是展示如何使用com.fasterxml.jackson.core.jsontoken的最佳示例。 我们使用了代码质 ...

rfedfre

ELENA编程语言简介

下载elena编译器源代码和示例—— 3.2 mb介绍elena是一个面向对象,面向对象,多态语言,带有后期绑定。 它具 ...

在C 中,键入安全多播回调

下载源代码- 3.3 kb介绍函数指针用于减少两段代码之间的耦合。 发布者定义回调函数签名并允许匿名注册函数指针。 订阅 ...

rfedfre

一步一步开发SOHO网络过滤器

下载源代码- 36.3 kb下载演示项目- 23 kb1.抽象大多数web过滤器都是内联的,这意味着所有传出和传入的包都 ...

rfedfre

高级AJAX列表框组件 v0.2

下载演示项目 13.9 kb下载源文件 7.8 kb介绍在中,我的上一篇文章我们创建了一个启用了客户端事件的asp.ne ...

rfedfre

使用 C#的多颜色 DropDownList

下载源 16.8 kb介绍本文演示如何读取系统颜色,并在下拉 list的每一行中显示颜色。 在本示例中,我将展示:如何从 ...

rfedfre

ASP.NET Ajax工具包TabStrip控件

下载源 599.6 kb介绍is asp.net ajax工具箱提供了优秀的选项卡控件,在每一个视图一次显示一个视图时组 ...

Java android.media.SoundPool 代码实例

以下是展示如何使用android.media.soundpool的最佳示例。 我们使用了代码质量辨别算法从开源项目中提取 ...

rfedfre

GridView数据组

下载源文件( c# ) 35.5 kb下载演示 60.6 kb介绍gridview 是以表格格式显示数据的最常用控件之一 ...

rfedfre

带插入选项的主细节 GridView

下载演示 92.6 kb下载源 82.3 kb介绍我必须在应用程序中实现一个主细节 gridview。 搜索网络,我找到 ...

rfedfre

带有搜索选项的ASP.NET GridView ( SearchableGridView )

下载演示 10.8 kb下载源 22.1 kb介绍我正在搜索一个方法,在 asp.net gridview控件中包含一个 ...

rfedfre

GridView的行级别 JavaScript

下载源文件 5.61 kb介绍这里示例说明如何将javascript方法/函数附加到行级别的asp.net gridvi ...

rfedfre

在 C# 中,CHTMLLogFile类

下载源 1.84 kb介绍为了跟踪应用程序的执行( 事件),日志文件可能有用。 通常,它们是在文件末尾添加行来记录事件的 ...

rfedfre

不那么简单的错误日志

下载源文件 26.5 kb下载演示项目 115 kb下载完整解决方案 158 kb下载架构 0.5 kb内容简介你能学到 ...

rfedfre

将调试/跟踪信息写入 XML

下载演示项目 10.4 kb介绍本文展示了如何创建 system.diagnostics.tracelistener的子 ...

rfedfre

事件日志和资源DLL业务流程

下载演示 134。下载源 58.8 kb图 1显示的默认事件日志消息内容简介限制值解决方案描述了问题。背景amp;起始点 ...

Java android.graphics.drawable.Animatable 代码实例

以下是展示如何使用android.graphics.drawable.animatable的最佳示例。 我们使用了代码质 ...