[乐意黎原创] glassfish里抛出Note: string:///XXX_jsp.java from uses unchecked or unsafe operations.

本文介绍了解决GlassFish服务器中出现的JSP编译错误的方法,特别是当设置genStrAsCharArray为true时引发的问题。通过将此参数设置为false可以避免因字符串过长导致的编译错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

glassfish里抛出如下错误:


org.apache.jasper.JasperException: PWC6033: Unable to compile class for JSP

PWC6199: Generated servlet error:
string:///XXXX_jsp.java:169: constant string too long

PWC6199: Generated servlet error:
Note: string:///XXXX_jsp.java from  uses unchecked or unsafe operations.


折腾了好久,始终找不到原因。
最后,经老大指点,并实际测试。终于发现原因 
是由于glassfish里 把genStrAsCharArray 项设为 true 导致的。
解决办法:



具体为:
把 $GLASSFISH_HOME/domains/domain1/config/default-web.xml 里的 
<param-name>genStrAsCharArray</param-name>
<param-value>true</param-value> 修改为:
<param-name>genStrAsCharArray</param-name>
<param-value>false</param-value>
 
 

genStrAsCharArray

false

If set to true, generates text strings as char arrays, which improves performance in some cases.

The default-web.xml file defines features such as filters and security constraints that apply to all web applications.  The parameter, development=true, (the default value for developer profile) enables changes made to JSPTM – code to be  instantly visible to the clients. However, there is a cost associated with this. To avoid the cost of checking whether the JSP code  has been modified and hence its recompilation, the first parameter, development=false, can be used to set development to false since this scenario is unlikely in a production system.  This check affects application scalability when multiple users request the same JSP class. The second parameter, genStrAsCharArray=true, changes the way the JSPs are generated by generating char arrays for every static strings in the JSP class like for example, the HTML tags.  By default, the JSPcode  writer must call the toCharArray() on every String on every invocation of the JSPclass.

Settings in  default-web.xml.  ($GLASSFISH_HOME/domains/domain1/config/default-web.xml)
<init-param>
<param-name>development</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>genStrAsCharArray</param-name>
<param-value>true</param-value> #-> 此处上面应该修改为false </init-param>

The more  configuration optimization can be done using the document from SUN you can download it 

With this setting all String values are declared as static char[] as follows:

static char[] _char_array_1 = "someString".toCharArray();

and used as follows:

out.write(_char_array_1);

instead of being used as follows:

out.write("someString");

This has two clear benefits:

  1. char[] has less memory overhead than String.
  2. The toCharArray() doesn't need to be (implicitly) called on every out.write(string) anymore.

Sounds like microoptimization, but those little bits counts a lot in a heavily visited website.

This setting is by the way not JBoss AS specific. It's Jasper specific, the JSP compiler of Apache Tomcat which is also used in under each JBoss AS and Sun Glassfish.

参考网址: http://docs.oracle.com/cd/E19879-01/820-4343/abedw/index.htmlhttp://www.binbert.com/blog/2010/04/glassfish-performance-tunning/
 

作者: 乐意黎,原创。禁止转载

原文地址: http://blog.csdn.net/aerchi/article/details/45394231

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值