Character encoding JSP -displayed wrong in JSP but not in URL: “á » á é » é”

后端 未结 10 1760
忘掉有多难
忘掉有多难 2020-12-03 08:24

I have this Web Application in JSP running on JBoss Application Server. I am using Servlets for friendly urls. I\'m sending search parameters through my JSP\'s and Servlets.

10条回答
  •  萌比男神i
    2020-12-03 08:41

    There are three layers to configure. From what you've described, it sounds like your problem lies in the database configuration.

    1. Browser Display and Form Submission

    JSP

    <%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
    

    HTML

    
    
    1. Web Server Processing

    JSP

    <%
      request.setCharacterEncoding("UTF-8");
      String name = request.getParameter("NAME");
    %>
    

    Same type of thing in a Servlet. See JBoss specific solution as well as complete server independent solution in this answer.

    1. Database Settings

    You may be losing the character information at the database level. Check to make sure your database encoding is UTF-8 also, and not ASCII.

    For a complete discussion of this topic, refer to Java article Character Conversions from Browser to Database.

提交回复
热议问题