Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 685617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:56:26+00:00 2026-05-14T01:56:26+00:00

I have a struts2 web application which accepts both POST and GET requests in

  • 0

I have a struts2 web application which accepts both POST and GET requests in many different charsets, does conversion of them into utf-8, displays the correct utf-8 characters on the screen and then writes them into utf-8 database.

I have tried at least 5 different methods for doing simple losless charset conversion of windows-1250 to utf-8 to start with, and all of them did not work. Utf-8 being the “larger set”, it should work without a problem (at least this is my understanding).

Can you propose how to do a charset conversion from windows-1250 to utf-8, and is it possible that struts2 is doing something weird with the params charset, which would explain why I can’t seem to get it right.

This is my latest attempt:

    String inputData = getSimpleParamValue("some_input_param_from_get");
    Charset inputCharset = Charset.forName("windows-1250");
    Charset utfCharset = Charset.forName("UTF-8");

    CharsetDecoder decoder = inputCharset.newDecoder();
    CharsetEncoder encoder = utfCharset.newEncoder();

    String decodedData = "";
    try {
        ByteBuffer inputBytes = ByteBuffer.wrap(inputData.getBytes()); // I've tried putting UTF-8 here as well, with no luck
        CharBuffer chars = decoder.decode(inputBytes);

        ByteBuffer utfBytes = encoder.encode(chars);
        decodedData = new String(utfBytes.array());

    } catch (CharacterCodingException e) {
        logger.error(e);
    }

Any ideas on what to try to get this working?

Thank you and best regards,

Bozo

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:56:27+00:00Added an answer on May 14, 2026 at 1:56 am

    I’m not sure of your scenario. In Java, a String is Unicode, one only deals with charset conversion when has to convert from/to String to/from a binary representation.
    In your example, when getSimpleParamValue(“some_input_param_from_get”) is called, inputData should already have the “correct” String, the conversion from the stream of bytes (that travelled from the client browser to the web server) to a string should have already taken part (responsability of the web server+web layer of your application).
    For this, I enforce UTF-8 for the web trasmission, placing a filter in the web.xml (before Struts), for example:

    public class CharsetFilter implements Filter {
    
        public void destroy() {}
    
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
            HttpServletRequest req = (HttpServletRequest) request;
            HttpServletResponse res = (HttpServletResponse) response;
            req.setCharacterEncoding("UTF-8");
    
            chain.doFilter(req, res);
            String contentType = res.getContentType(); 
            if( contentType !=null && contentType.startsWith("text/html"))
                res.setCharacterEncoding("UTF-8");
        }
    
        public void init(FilterConfig filterConfig) throws ServletException {
        }
    }
    

    If you cannot do this, and if your getSimpleParamValue() “errs” in the charset conversion (eg: it assumed the byte stream was UTF-8 and was windows-1250) you now have an “incorrect” string, and you must try to recover it by undoing and redoing the byte-to-string conversion – in which case you must know the wrong AND the correct charset – and, worse, deal with the possibity of missing chars (if it was interpreted as UTF8, i maight have found illegal char sequence).
    If you have to deal with this in a Struts2 action, I’d say you are in problems, you should deal with it explicitly before/after it (in the upper web layer – or in the Database driver or File encoding or whatever)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a Struts2 web application which uses tiles however I have discovered
I have a web application which runs on MySQL, and uses Java, Struts2 and
I have a web application developed with Struts2, JSP, JPA, Spring and MySql. I
I have one legacy web application based on struts2 (primarily using annotation). While debugging
I have a web application, which was designed and always worked under root context
I have struts2 web application. Right now I need embed with help of iframe
I am developing a web application in struts2. I have declared global properties in
I have an already developed web application based on struts 1.2 which contains jsp
I am using struts2 for developing a web application. I have include the required
I have a struts2 web application with tiles. I need to make header, sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.