jsp不以正确的格式传递UTF-8数据 [英] jsp not passing UTF-8 data in proper format

查看:116
本文介绍了jsp不以正确的格式传递UTF-8数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要JSP页面支持UTF8数据我可以使用struts2和jsp本地化,但是当我从本地语言的jsp从用户采取数据时,信息不会以正确的格式进行操作,它传递一些grabled数据。
这是我的jsp代码:------

I want JSP pages to support UTF8 data I am able to localization with struts2 and jsp but when I take data from user on jsp in local language the information is not going in action in proper format it is passing some grabled data. Here is my jsp code :------

<%@ page language="java" contentType="text/plain; charset=UTF-8"
    pageEncoding="UTF-8"%>
      <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page import="java.util.*"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/plain; charset=UTF-8">
<title><s:text name="global.addnewcustomer"/></title>
<script type="text/javascript" src="http://localhost:9090/AMCMSWeb/basic/validation/Login.js">
</script>
</head>
<body>
<h2 align="center"><s:text name="global.fillinfo"/></h2>
    <s:form action="addcustomeraction" method="post" acceptcharset="UTF-8">

<table align="center" border="1" bgcolor="pink" bordercolor="gray">
<tr>
    <td><s:text name="global.custName"/></td>
    <td>:</td>
    <td><s:textfield name="custName" size="15"></s:textfield></td>
    <td><s:text name="global.custMidleName"/></td><td>:</td><td><s:textfield name="custMidleName" size="15"></s:textfield></td>
    <td><s:text name="global.custLastName"/></td><td>:</td><td><s:textfield name="custLastName" size="15"></s:textfield></td>
</tr>
<tr>
    <td><s:text name="global.mobileNo"/></td><td>:</td><td><s:textfield name="mobileNo" size="15"></s:textfield></td>
    <td><s:text name="global.phoneNo"/></td><td>:</td><td><s:textfield name="phoneNo" size="15"></s:textfield></td>
    <td><s:text name="global.toDate"/>&nbsp;<s:label>(mmm/dd/yyyy)</s:label></td><td>:</td><td><s:textfield name="toDate" size="15" readonly="true">
                <s:param name="value">
                        <s:date name="new java.util.Date()" format="MM/dd/yyyy"/>
                </s:param>
    </s:textfield></td>
</tr>
<tr>
    <td><s:text name="global.atPost"/></td><td>:</td><td><s:textarea name="atPost" cols="15" rows="3"></s:textarea></td>
</tr>
<tr>
    <td><s:text name="global.taluka"/></td><td>:</td><td><s:select list="#{'Miraj':'Miraj','Haveli':'Haveli'}" name="taluka" headerKey="-1" headerValue="Select Taluka" ></s:select></td>
    <td><s:text name="global.district"/></td><td>:</td><td><s:select list="#{'Sangli':'Sangli','Pune':'Pune'}" name="district" headerKey="-1" headerValue="Select District"></s:select></td>
</tr>
<tr>
    <td><s:text name="global.state"/></td>
    <td>:</td>
    <td><s:select list="#{'Maharashtra':'Maharashtra','Karnataka':'Karnataka'}" name="state" headerKey="-1" headerValue="Select State" onchange="list_districts()"></s:select></td>
    <td><s:text name="global.country"/></td><td>:</td><td><s:select  list="#{'India':'India'}" name="country" headerKey="-1" headerValue="Select Country" ></s:select></td>
</tr>
<tr>
    <td><s:text name="global.pinCode"/></td>
    <td>:</td>
    <td><s:textfield name="pinCode"  type="" size="15"></s:textfield></td>
</tr>
</table>

<table align="center" >
     <tr>
        <td><s:submit name="s" key="global.proceed"/></td>  
        <td><input type="button" name="cancel" value="  X  "></td>
     </tr>
</table>
    </s:form>
</body>
</html> 


推荐答案

页面中指定的字符编码web.xml)应用于HTTP通信的以下阶段:

The character encoding specified in the page (or in the web.xml) is applied to the following phases of an HTTP communication:


  1. 准备/从客户端向服务器发送请求

  2. 在服务器中接收/读取请求

  3. 准备从服务器到客户端的响应

  4. 在客户端接收/读取响应

应用服务器只需负责第2阶段。

您需要查找您的特定应用程序服务器设置,以更改默认字符编码(可以轻松地 ISO-8859-1 ),并将其更改为 UTF-8

You need to look for your specific application server settings, to alter the default character encoding (that could easily be ISO-8859-1), and alter it to work in UTF-8.

例如,在Tomcat中,您需要编辑 conf / server.xml 文件,方法是添加 URIEncoding =UTF-8 / code>的 / code>参数,例如从

For example, in Tomcat you would need to edit the conf/server.xml file, by adding the URIEncoding="UTF-8" parameter to the <Connector>, for example from

<Connector port="8090" />

<Connector port="8090" URIEncoding="UTF-8"/>

在Apache Wiki中有一个很好的列表,要检查,以确保所有的组件都以UTF-8运行:

In the Apache Wiki there is a nice list of things to check to make sure all your components are running in UTF-8:


你能推荐什么才能使一切正常? (如何使用UTF-8
无处不在)。

使用UTF-8作为一切的字符编码是一个安全的赌注。
这几乎适用于所有情况。

Using UTF-8 as your character encoding for everything is a safe bet. This should work for pretty much every situation.

为了完全切换到使用UTF-8,你需要使

In order to completely switch to using UTF-8, you need to make the following changes:


  1. 在server.xml中设置URIEncoding =UTF-8。参考文献: HTTP
    连接器

    AJP
    连接器

  2. 使用字符编码过滤器
    默认编码设置为UTF-8

  3. 更改所有JSP以在其contentType中包含字符集名称。例如,对于通常的JSP页面使用<%@ page contentType =text / html; charset = UTF-8%>
    ,对于XML语法中的页面,c $ c>< jsp:directive.page
    contentType =text / html; charset = UTF-8/>


  4. 更改所有servlet以设置响应的内容类型,并将内容类型中的charset名称包含为UTF-8。使用
    response.setContentType(text / html; charset = UTF-8)
    response.setCharacterEncoding

  5. 更改您使用的任何内容生成库(Velocity,Freemarker等)使用UTF-8并指定UTF-

  6. 在您的字符编码过滤器或jsp页面有机会设置之前,禁用任何可能读取请求参数的阀门或过滤器
    编码为UTF-8。有关详细信息,请参阅
    http://www.mail -archive.com/users@tomcat.apache.org/msg21117.html

  1. Set URIEncoding="UTF-8" on your in server.xml. References: HTTP Connector, AJP Connector.
  2. Use a character encoding filter with the default encoding set to UTF-8
  3. Change all your JSPs to include charset name in their contentType. For example, use <%@page contentType="text/html; charset=UTF-8" %> for the usual JSP pages and <jsp:directive.page contentType="text/html; charset=UTF-8" /> for the pages in XML syntax (aka JSP Documents).
  4. Change all your servlets to set the content type for responses and to include charset name in the content type to be UTF-8. Use response.setContentType("text/html; charset=UTF-8") or response.setCharacterEncoding("UTF-8").
  5. Change any content-generation libraries you use (Velocity, Freemarker, etc.) to use UTF-8 and to specify UTF-8 in the content type of the responses that they generate.
  6. Disable any valves or filters that may read request parameters before your character encoding filter or jsp page has a chance to set the encoding to UTF-8. For more information see http://www.mail-archive.com/users@tomcat.apache.org/msg21117.html.


这篇关于jsp不以正确的格式传递UTF-8数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆