jsp调用java中的常量,JSP常量字符串太长

I've create a jsp page like this:

if(myName == null)

{ String redirectURL = "http://www.google.com";

response.sendRedirect(redirectURL);

}

%>

... some content ...

The content inside html tage is around 100k. Now when I try to compile and run it in netbean/glassfish, i got an error message:

constant string too long

out.write(".......

I read it somewhere that there's a 64k limit. but i am not using "out.write" function at all, the jsp section is really small as you can see. How did this happen and how do I solve this?

What I want to achieve is first check if the session is valid, if not then redirect. if so, then show content. The content is quite large and static but i have no control over it :(. anyway i can achieve this?

解决方案

but i am not using "out.write" function at all

JSP is internally using it. You know, JSP file is during "JSP compile" step converted to a Java class extending HttpServlet and everything ends up as Java code. Checkout the generated code in server's work folder to see it yourself.

Use runtime JSP includes using to split out large fragments into separate JSP files.

E.g.

Content

Or, if that doesn't suit the concrete functional requirement, an alternative, provided that the HTML content is really static (i.e. it does not contain any JSP scriptlets, tags, expressions, etc), is to put the HTML content in its own some.html file and reference it by JSTL .

...

This way it doesn't end up as part of JSP source code.

Unrelated to the concrete problem, your redirect logic is missing a return statement. When executing the redirect, all the remaining JSP code is otherwise still invoked. Also, if you're repeating this scriptlet over all JSP files, you'd question if you can't better use a servlet filter for the job.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值