Java Code Inside Page Directive

Discussion in 'Java' started by vunet.us@gmail.com, Jul 31, 2007.

  1. Guest

    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.
    , Jul 31, 2007
    #1
    1. Advertising

  2. Wojtek Guest

    wrote :
    > 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...se.html#setCharacterEncoding(java.lang.String)

    --
    Wojtek :)
    Wojtek, Jul 31, 2007
    #2
    1. Advertising

  3. Guest

    , Jul 31, 2007
    #3
  4. Wojtek Guest

    wrote :
    >>
    >> You can however use response.setCharacterEncoding("UTF-8")
    >>
    >> http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletResponse.h...)

    >
    >
    > 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."

    --
    Wojtek :)
    Wojtek, Jul 31, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U3RldmUgVHJhbmRhaGw=?=

    using directive w/o code-behind

    =?Utf-8?B?U3RldmUgVHJhbmRhaGw=?=, Jun 12, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    623
    =?Utf-8?B?U3RldmUgVHJhbmRhaGw=?=
    Jun 12, 2006
  2. Jeff
    Replies:
    3
    Views:
    459
    Mark Rae
    Jan 17, 2007
  3. timjowers
    Replies:
    7
    Views:
    4,343
    heyjude
    Feb 2, 2011
  4. Niels Dekker - no reply address

    Using-declaration or using-directive inside unnamed-namespace?

    Niels Dekker - no reply address, Apr 27, 2010, in forum: C++
    Replies:
    1
    Views:
    588
    Niels Dekker - no reply address
    Apr 27, 2010
  5. Philip

    Page Directive - New Page Properties

    Philip, Mar 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    115
    Philip
    Mar 21, 2006
Loading...

Share This Page