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.