java – jsp没有以适当的格式传递UTF-8数据
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – jsp没有以适当的格式传递UTF-8数据,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4871字,纯文字阅读大概需要7分钟。
内容图文
![java – jsp没有以适当的格式传递UTF-8数据](/upload/InfoBanner/zyjiaocheng/703/42f6d4c04a9940eab95b510500a79758.jpg)
我希望JSP页面支持UTF8数据我能够使用struts2和jsp进行本地化但是当我用本地语言从jsp上的用户获取数据时,信息不能以正确的格式运行,而是传递一些grabled数据.
这是我的jsp代码:——
<%@ 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"/> <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通信的以下阶段:
>准备/从客户端向服务器发送请求
>在服务器中接收/读取请求
>准备/从服务器向客户端发送响应
>在客户端接收/读取响应
Application Server是第2阶段的唯一负责人.
您需要查找特定的应用程序服务器设置,以更改默认字符编码(可以很容易地为ISO-8859-1),并将其更改为在UTF-8中工作.
例如,在Tomcat中,您需要编辑conf / server.xml文件,方法是将URIEncoding =“UTF-8”参数添加到< Connector>,例如
<Connector port="8090" />
至
<Connector port="8090" URIEncoding="UTF-8"/>
In the Apache Wiki there is a nice list of things to check以确保所有组件都以UTF-8运行:
What can you recommend to just make everything work? (How to use UTF-8
everywhere).Using UTF-8 as your character encoding for everything is a safe bet.
This should work for pretty much every situation.In order to completely switch to using UTF-8, you need to make the
following changes:
- Set URIEncoding=”UTF-8″ on your in server.xml. References: 07001,
07002.- Use a 07003 with
the default encoding set to UTF-8- 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
for the pages in XML syntax
contentType="text/html; charset=UTF-8" />
(aka JSP Documents).- 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")
.- 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.- 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
07004.
内容总结
以上是互联网集市为您收集整理的java – jsp没有以适当的格式传递UTF-8数据全部内容,希望文章能够帮你解决java – jsp没有以适当的格式传递UTF-8数据所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。