Java Code Inside Page Directive

V

vunet.us

Hello,
I want to use somE Java code inside of my page directive for JSP page
such as:

<%@page contentType="text/html;charset=XXXXX_JAVA_CODE_HERE_XXXXX" %>

XXXXX_JAVA_CODE_HERE_XXXXX should be some string I set dynamically:
public static String = "UTF-8";

Please, recommend a solution. Thanks.
 
W

Wojtek

Hello,
I want to use somE Java code inside of my page directive for JSP page
such as:

<%@page contentType="text/html;charset=XXXXX_JAVA_CODE_HERE_XXXXX" %>

XXXXX_JAVA_CODE_HERE_XXXXX should be some string I set dynamically:
public static String = "UTF-8";

Please, recommend a solution. Thanks.

You cannot. A directive is for the compiler and is not processed during
runtime.

You can however use response.setCharacterEncoding("UTF-8")

http://java.sun.com/j2ee/1.4/docs/a...e.html#setCharacterEncoding(java.lang.String)
 
W

Wojtek

Can I use response.setCharacterEncoding("utf-8"); on a JSP page?

Did you read the JavaDoc? It is all explained in there:

"This method can be called repeatedly to change the character encoding.
This method has no effect if it is called after getWriter has been
called or after the response has been committed."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top