SSH框架中文乱码问题

敷衍师 2013-08-10 10:36:33
小弟做了一个SSH框架的项目,在页面表单中的数据上传到action时出现乱码。

上网找了很多资料,说用拦截器,但是不知道是不是我的Web.xml里面配置了Struts2的缘故!
	<!--Struts框架配置-->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>admin/login.jsp</welcome-file>
</welcome-file-list>



不知道是不因为这样,我总是调用不了我的拦截器。总之一句话,就是不起作用,它该怎么乱码还是怎么乱码~~~~~

我现在用的是Spring拦截器。
<filter> 
<filter-name>Set Character Encoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>



页面效果



中文的那些是在数据库手动打进去的,也就是说从数据库读取数据是没问题的。求告知,求鞭策,坐等。。。。
...全文
369 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
敷衍师 2014-03-25
  • 打赏
  • 举报
回复
好久了啊。。。咳咳,当初烦这个错误是因为:我的form表单没加POST提交方式、、、、
abote123 2013-12-29
  • 打赏
  • 举报
回复
我也遇到了同样的中文乱码问题,我把整个工程都设成了utf-8的编码,提交中文表单数据后显示出来就是乱码,求高人指教!
ljm653467 2013-08-13
  • 打赏
  • 举报
回复
看一下struts.xml有没有 <?xml version="1.0" encoding="UTF-8"?> 还不行就是mysql数据库表要设置为UTF-8了,因为你是在数据库写了之后在页面显示。 持续关注中!
oh_Maxy 2013-08-10
  • 打赏
  • 举报
回复
productsParameteraddnewParameter这个action在哪配置的?对应的类是什么?
敷衍师 2013-08-10
  • 打赏
  • 举报
回复
引用 3 楼 chenguangafter 的回复:
看看jsp文件的编码,jsp页面中meta属性可以加编码,这些都试试。
大哥。我不懂得,你最好在详细点。最好贴出代码、
afterTheDream 2013-08-10
  • 打赏
  • 举报
回复
看看jsp文件的编码,jsp页面中meta属性可以加编码,这些都试试。
敷衍师 2013-08-10
  • 打赏
  • 举报
回复
引用 1 楼 oh_Maxy 的回复:
页面代码和Action代码贴出来看看。
页面代码:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="/struts-dojo-tags" prefix="sx" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'productstype.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
  <s:debug></s:debug>
  商品分类:<s:property value="#session.proType.proTypeName"/>
  <form action="productsParameteraddnewParameter">
   		<table>
   			<tr>
   				<td>参数编号</td>
   				<td>参数名称</td>
   				<td>参数描述</td>
   				<td>参数操作</td>
   			</tr>
   			<s:iterator value="#session.proType.sfblProductsParameters" var="s">
   			<s:if test="#s!=null">
   			<tr>
   				<td><s:property value="%{#s.productsParameterId}"/></td>
   				<td><s:property value="%{#s.productsParameterName}"/></td>
   				<td><s:property value="%{#s.productsParameterInfo}"/></td>
   				<td><sx:a href="getproductsTypeactiongetProductsTypeById?id=%{#pt.proTypeId}"  targets="content">编辑</sx:a><sx:a href="productsParameterdeleteParameter?id=%{#s.productsParameterId}"  targets="content">删除</sx:a></td>
   			</tr>
   			</s:if><s:else>
   				<tr><td>暂无任何参数信息</td></tr>
   			</s:else>
   			</s:iterator>
   			<tr>
   				<td><input type="text" name="par.productsParameterName"></td>
   				<td><input type="text" name="par.productsParameterInfo"></td>
   				<td><sx:submit targets="content"></sx:submit></td>
   			</tr>
   		</table>
   		</form>
  </body>
</html>
后台代码很简单,就是用的Spring自动封装,但是接过来,去对象查看时就是乱码了。
	public SfblProductsParameter par;

	public SfblProductsParameter getPar() {
		return par;
	}

	public void setPar(SfblProductsParameter par) {
		this.par = par;
	}
oh_Maxy 2013-08-10
  • 打赏
  • 举报
回复
页面代码和Action代码贴出来看看。
敷衍师 2013-08-10
  • 打赏
  • 举报
回复
敷衍师 2013-08-10
  • 打赏
  • 举报
回复
哪里的编码啊。。页面还是xml
s3323931 2013-08-10
  • 打赏
  • 举报
回复
把编码设为utf-8试试
敷衍师 2013-08-10
  • 打赏
  • 举报
回复
这样吧 我在登陆的时候呢。我把数据库的登陆名称变成中文了。之后,现在在登陆框里只要是写中文传上去就是刚才你看到的这种乱码。 现在登录都上不去了。 哈哈哈哈。 我和别人的区别只是在 spring的applicationContext.xml的数据库连接设置的时候设置了上传到数据库的乱码处理! 其他的都是跟你们写的一模一样的
	<property name="url"  value="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8"></property>
	
我要崩溃了、我的QQ是200739491 可以的话,加我QQ跟我说。唉~~~~

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧