爱派苹果升级后连不上电脑无线网了,手机的无线网无法分享给爱派?可是我连的wifi是别人家的没有密码咋办呢?

查看: 4888|回复: 17
JSP页面中提交表单出现乱码
论坛徽章:0
在JSP页面中提交表单参数时,参数是中文,servlet取得参数后执行一个insert后数据库中应为中文的地方出现了乱码,然后转发到的另一个页面中是中文的地方也变为乱码,请问该怎么解决啊??我在JSP页面中编码的地方都设置为gb2312了,一般的中文显示不出问题,但是表单提交时却出现了乱码问题。我按书上写了一个filter,结果主页也打不开了。请高手帮忙解决一下啊!谢谢!
论坛徽章:130
大学生你动手能力也太差了点吧, 别一点事就问啊问
论坛徽章:0
可以写个方法转一下。
public String getEncodedStr(String str )throws Exception{
& & & & & & & & return new String( str.getBytes(&8859_1&), “gb2312”);
论坛徽章:0
原帖由 zgl81929 于
15:12 发表
可以写个方法转一下。
public String getEncodedStr(String str )throws Exception{
& & & & & & & & return new String( str.getBytes(&8859_1&), “gb2312”);
request.setCharacterEncoding(&gb2312&);
论坛徽章:53
这个问题已经有很多回答了,基本上仔细浏览一下都能解决
论坛徽章:0
哦 谢谢啊!我用了String describle=new String(request.getParameter(&describle&).getBytes(&ISO8859-1&),&GBK&);后虽然能显示中文了,但是数据库中的中文后面多了□□□□□□这样的东西,我试试把&GBK&改为&gb2312&看看。 问啊问的主要是为了节约时间啊~呵呵
[ 本帖最后由 yflijet 于
14:12 编辑 ]
论坛徽章:0
我修改了几次描述信息(我实现的一个功能)后(比如添加描述信息,清空描述信息),还是有那些框框,而且越来越多了。不知道怎么回事。
[ 本帖最后由 yflijet 于
14:23 编辑 ]
论坛徽章:130
你要知道造成乱码的原理, 就在那闭着眼瞎改怎么行
论坛徽章:0
回复 #8 justforregister 的帖子
乱码的原理?之前看过一点,不过时间不多了所以没细细地去研究啊,呵呵
论坛徽章:0
还是存在这个问题,写入的时候也是.我的JSP页面编码全为gb2312。我恨乱码!!
itpub.net All Right Reserved. 北京皓辰网域网络信息技术有限公司版权所有    
 北京市公安局海淀分局网监中心备案编号: 广播电视节目制作经营许可证:编号(京)字第1149号温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
All the splendor in the world is not worth a good friend!!
Hello my friend!!
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(7296)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
在LOFTER的更多文章
loftPermalink:'',
id:'fks_095069',
blogTitle:'jQuery load()加载jsp页面且传递中文乱码问题的解决',
blogAbstract:'
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}11955人阅读
&&Servelet
首先,检查你的 /usr/share/fonts/ttf/gb 目录下是否装有中文字体 gbsn00lp.ttf 。如果没有,也可以用 Windows 字体目录下的 song.ttf 来代替。将字体文件拷贝到 Java 安装目录下的 jre/lib/fonts 下。第二,修改 Java 安装目录下的 jre/lib/fonts/fonts.dir 文件,将首行的 72 改为 73,然后添加下列内容:gbsn00lp.ttf -Arphic Technology Co.-AR PL SungtiL GB-medium-r-normal--0-0-0-0-c-0-gb如果你用的是 song.ttf ,则应该将头部的 gbsn00lp.ttf 改为 song.ttf 。第三,在 Java 安装目录下的 jre/lib 目录中,将字体配置文件 font.properties.zh.Turbo 复制为 font.properties.zh 。然后修改 font.properties.zh 。将文件中所有的:-tlc-song-medium-r-normal--*-%d-*-*-c-*-gbk-0 替换为:-Arphic Technology Co.-AR PL SungtiL GB-medium-r-normal--0-0-0-0-c-0-gb第四,用 JDK 自带的演示程序 SwingSet2 测试,如果看到中文菜单则说明设置成功。
1.在Web.xml中配置过滤器:
See the NOTICE file distributed with
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
* &p&Example filter that sets the character encoding to be used in parsing the
* incoming request, either unconditionally or only if the client did not
* specify a character encoding.& Configuration of this filter is based on
* the following initialization parameters:&/p&
* &li&&strong&encoding&/strong& - The character encoding to be configured
*&&&& for this request, either conditionally or unconditionally based on
*&&&& the &code&ignore&/code& initialization parameter.& This parameter
*&&&& is required, so there is no default.&/li&
* &li&&strong&ignore&/strong& - If set to "true", any character encoding
*&&&& specified by the client is ignored, and the value returned by the
*&&&& &code&selectEncoding()&/code& method is set.& If set to "false,
*&&&& &code&selectEncoding()&/code& is called &strong&only&/strong& if the
*&&&& client has not already specified an encoding.& By default, this
*&&&& parameter is set to "true".&/li&
* &p&Although this filter can be used unchanged, it is also easy to
* subclass it and make the &code&selectEncoding()&/code& method more
* intelligent about what encoding to choose, based on characteristics of
* the incoming request (such as the values of the &code&Accept-Language&/code&
* and &code&User-Agent&/code& headers, or a value stashed in the current
* user's session.&/p&
* @author Craig McClanahan
* @version $Revision: 466607 $ $Date:
17:09:50 -0600 (Sat, 21 Oct 2006) $
// ----------------------------------------------------- Instance Variables
* The default character encoding to set for requests that pass through
* this filter.
protected String encoding =
* The filter configuration object we are associated with.& If this value
* is null, this filter instance is not currently configured.
protected FilterConfig filterConfig =
* Should a character encoding specified by the client be ignored?
protected boolean ignore =
// --------------------------------------------------------- Public Methods
* Take this filter out of service.
public void destroy() {
this.encoding =
this.filterConfig =
* Select and set (if specified) the character encoding to be used to
* interpret request parameters for this request.
* @param request The servlet request we are processing
* @param result The servlet response we are creating
* @param chain The filter chain we are processing
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet error occurs
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
// Conditionally select and set the character encoding to be used
if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null)
request.setCharacterEncoding(encoding);
// Pass control on to the next filter
chain.doFilter(request, response);
* Place this filter into service.
* @param filterConfig The filter configuration object
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterC
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if (value == null)
this.ignore =
else if (value.equalsIgnoreCase("true"))
this.ignore =
else if (value.equalsIgnoreCase("yes"))
this.ignore =
&&&&&&&&&& this.ignore =
// ------------------------------------------------------ Protected Methods
* Select an appropriate character encoding to be used, based on the
* characteristics of the current request and/or filter initialization
* parameters.& If no character encoding should be set, return
* &code&null&/code&.
* The default implementation unconditionally returns the value configured
* by the &strong&encoding&/strong& initialization parameter for this
* @param request The servlet request we are processing
protected String selectEncoding(ServletRequest request) {
return (this.encoding);
&Connector port="8080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
&&&&&&&&&enableLookups="false" redirectPort="8443" acceptCount="100"
&&&&&&connectionTimeout="20000" disableUploadTimeout="true"& URIEncoding=&TUF-8& useBodyEncodingForURI="true"./&
&&相关文章推荐
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:177338次
积分:1302
积分:1302
排名:千里之外
原创:10篇
转载:16篇
(3)(1)(1)(1)(1)(1)(2)(1)(1)(1)(6)(4)(3)分享JSP中文乱码解决方法
投稿:hebedich
字体:[ ] 类型:转载 时间:
本文给大家分享的是4种jsp中出现中文乱码的解决方法,非常的细致全面,并附上具体的示例,推荐给大家,有需要的小伙伴可以参考下。
一、JSP页面中文乱码
在JSP页面中,中文显示乱码有两种情况:一种是HTML中的中文乱码,另一种是在JSP中动态输出的中文乱码。
先看一个JSP程序:
&%@ page language="java" import="java.util.*" %&
&title&中文显示示例&/title&
这是一个中文显示示例:
String str = "中文";
out.print(str);
上面这个JSP程序看起来好像是在页面显示几句中文而且标题也是中文。运行后在浏览器中显示如图所示
原因在于没有在JSP中指定页面显示的编码,消除乱码的解决方案很简单上面代码中page命令修改成如下所示即可
&%@ page language="java" import="java.util.*" contentType="text/ charset=GB2312" %&
&title&中文显示示例&/title&
这是一个中文显示示例:
String str = "中文";
out.print(str);
再次运行乱码消失,原理就是向页面指定编码为GB2312,那么页面就会按照此编码来显示,于是乱码消失。
二、URL传递参数中文乱码
一般情况下在使用get方法提交表单的时候传递的参数如果是中文的话很可能会出现乱码。
下面是一个示例程序
&%@ page language="java" import="java.util.*" contentType="text/charset=gb2312"%&
&title&URL传递参数中文处理示例&/title&
String param = request.getParameter("param");
&a href="URLCharset.jsp?param='中文'"&请点击这个链接&/a&&br&
你提交的参数为:&%=param%&
上面这个JSP程序的功能就是通过一个URL链接向自身传递一个参数,这个参数是中文字符串,这个程序的运行效果如下图
对于URL传递中文参数乱码这个问题,其处理方法比较特殊,仅仅转换这个中文字符串或者设置JSP页面显示编码都是不能解决问题的,需要修改Tomcat服务器的配置文件才能解决问题。在这里修改Tomcat的conf目录下的server.xml配置文件,具体改后的代码如下
&Connector port="8080" protocol="HTTP/1.1" URIEncoding="gb2312"
connectionTimeout="20000"
redirectPort="8443" /&
在原来代码中添加URI编码设置URIEncoding=“gb2312”即可,重启Tomcat服务器可以得到正确的页面。其原理也和上面的情况类似,就是向程序指明编码类型,然后显示就正常了。
三、表单提交中文乱码
对于表单的数据可以使用request.getParameter(“”)的方法获取,但是当表单中出现中文数据的时候就会出现乱码。
示例代码如下
&%@ page language="java" import="java.util.*" contentType="text/charset=gb2312"%&
&title&Form中文处理示例&/title&
&font size="2"&
下面是表单内容:
&form action="AcceptFormCharset.jsp" method="post"&
用户名:&input type="text" name="userName" size="10"/&
密 码:&input type="password" name="password" size="10"/&
&input type="submit" value="提交"&
在上面的表单当中想AcceptFormCharset这个页面提价两项数据,下面是AcceptFormCharset.jsp的内容:
&%@ page language="java" import="java.util.*"
contentType="text/charset=gb2312"%&
&title&Form中文乱码&/title&
&font size="2"& 下面是表单提交以后用request取到的表单数据:&br&
String userName = request.getParameter("userName");
String password = request.getParameter("password");
out.println("表单输入userName的值:" + userName + "&br&");
out.println("表单输入password的值:" + password + "&br&");
在上面的程序中,如果表单输入没有中文,则可以正常的显示当输入的数据中有中文的时候,得到的结果如图所示。
产生种结果的原因是Tomcat中对于post方法提交的表单采用的默认编码为ISO-8859-1,而这种编码格式不支持中文字符。对于这个问题可以采用转换编码格式的方法来解决,现在对AcceptFromCharset这个页面改动如下:
&%@ page language="java" import="java.util.*"
contentType="text/charset=gb2312"%&
&title&Form中文乱码&/title&
&font size="2"& 下面是表单提交以后用request取到的表单数据:&br&
String userName = request.getParameter("userName");
String password = request.getParameter("password");
out.println("表单输入userName的值:" + new String(userName.getBytes("ISO-8859-1"), "gb2312")+ "&br&");
out.println("表单输入password的值:" + new String(password.getBytes("ISO-8859-1"), "gb2312")+ "&br&");
经过这样的转换编码以后,所有的中文输入都可以用request对象正常取出。在上面这个程序中,第四行和第五行是转换编码格式的关键,先从ISO-8859-1格式的字符串中取出字节内容,然后在用GB2312的编码格式重新构造一个新的字符串。这样就可以支持中文变淡输入的正常取值和显示。改进以后程序运行结果如下
经过上面的更改编码格式的处理,表单的中文输入乱码问题已经得到解决。但是如果上面的表单中的输入项不止是两个,那么每个输入项都需要进行编码转换,那样就很麻烦了。这是我们就用到了大名鼎鼎的过滤器filter了。关于这里的内容大致的思虑和上面的一样具体做法请参照笔者的。
四、Eclipse中JSP文件中文乱码
在Eclipse或者MyEclipse中由于默认的JSP编码格式为ISO-8859-1,所以当打开由其他编辑器编辑的JSP文件时会出现乱码,如图所示
对于这个问题我们只需要更改一下Eclipse或者是MyEclipse中对JSP的默认编码就可以了,修改的地方(我的MyEclipse版本为11)如图所示
在Eclipse或者MyEclipse当中JSP文件默认的编码为ISO-8859-1,所以在JSP代码中间如果出现中文就不能保存,例如如下代码
&%@ page language="java" import="java.util.*" %&
&title&中文显示示例&/title&
这是一个中文显示示例:
String str = "中文";
out.print(str);
修改后在保存的时候会提示如下:
现这个提示的原因在于JSP源文件中有ISO=8859-1编码无法识别的中文字符,对于这个问题,解决办法就是在JSP页面中声明页面编码格式即可。声明后代码如下:
&%@ page language="java" import="java.util.*" pageEncoding="GB2312" %&
&title&中文显示示例&/title&
这是一个中文显示示例:
String str = "中文";
out.print(str);
其中第一行中pageEncoding=“gb2312”指明了JSP页面编码采用GB2312,这样就可以正常保存JSP的源文件了。
以上就是本文所述的全部内容了,希望大家能够喜欢。
请您花一点时间将文章分享给您的朋友或者留下评论。我们将会由衷感谢您的支持!
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具如何解决JSP页面显示乱码问题
&一、JSP页面显示乱码二、表单提交中文时出现乱码三、数据库连接时出现乱码大家在JSP的开发过程中,经常出现中文乱码的问题,可能一至困扰着您,我现在把我在JSP开发中遇到的中文乱码的问题及解决办法写出来供大家参考。一、JSP页面显示乱码下面的显示页面(display.jsp)就出现乱码:&%out.print(&JSP的中文处理&);%&对不同的和不同的JDK版本,处理结果就不一样。原因:服务器使用的编码方式不同和浏览器对不同的字符显示结果不同而导致的。解决办法:在JSP页面中指定编码方式(gb2312),即在页面的第一行加上:英文代码&%@ page contentType=&text/ charset=gb2312&%&就可以消除乱码了。完整页面如下:&%@ page contentType=&text/ charset=gb2312&%&&%out.print(&JSP的中文处理&);%&二、表单提交中文时出现乱码下面是一个提交页面(submit.jsp),
【声明】:黑吧安全网()登载此文出于传递更多信息之目的,并不代表本站赞同其观点和对其真实性负责,仅适于网络安全技术爱好者学习研究使用,学习中请遵循国家相关法律法规。如有问题请联系我们,联系邮箱,我们会在最短的时间内进行处理。
上一篇:【】【】}

我要回帖

更多关于 ios11升级后连不上网 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信