sturt2乱码问题,网上的答案还是解决不了,谢谢大家帮忙

fengxiaowenhappy 2009-08-29 09:08:54
booktoadd.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>

<body>
<form action="bookaction.action" name="bookform">

<table width="30%" border="1" cellpadding="1" cellspacing="0"
align="center">
<tr>
<td>
ISBN
</td>
<td>
<s:textfield name="isbn" theme="simple"></s:textfield>
</td>
</tr>
<tr>
<td>
书名
</td>

<td>
<s:textfield name="name" theme="simple"></s:textfield>
</td>
</tr>部分省略。。。

BookAction.java
public class BookAction extends ActionSupport implements ModelDriven<Book> {

private BookService bookservice;
private List books;
private Book book = new Book();
private String[] ids;
public String addbook() throws Exception {
bookservice.add(book);
return "addsuccess";
}
//get和set省略.....

}

struts.xml
<struts>
<include file="struts-default.xml"/>
<constant name="struts.objectFactory" value="spring"/>
<constant name="struts.i18n.encoding" value="UTF-8"/>
<constant name="struts.locale" value="zh_CN"/>
<constant name="struts.serve.static.browserCache" value="false"/>
<constant name="struts.url.includeParams" value="none"/>
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
<constant name="struts.devMode" value="false"/>
<constant name="struts.ui.theme" value="simple"/>

<package name="book" extends="struts-default">
<action name="bookaction" class="com.book.action.BookAction">
<result name="books">booklist.jsp</result>
<result name="addsuccess" type="redirect">bookaction.action</result>
<result name="deletesuccess" type="redirect">bookaction.action</result>
<result name="toaddsuccess">booktoadd.jsp</result>
<result name="book">booktoupdate.jsp</result>
<result name="updatesuccess" type="redirect">bookaction.action</result>
</action>

</package>
web.xml
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>


<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!-- 防止乱码的过滤器 -->
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ActionContextCleanUp
</filter-class>
</filter>

<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

</web-app>

问题所在:添加book时,BookAction的属性book中的中文字段显示乱码。
...全文
87 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
qustgjk 2009-08-29
  • 打赏
  • 举报
回复
在struts.xml中配置常量 <constant name="struts.i18n.encoding" value="GB2312(或其他编码方式)></constant>
sangshusen_1988 2009-08-29
  • 打赏
  • 举报
回复
看是在哪里出的乱码?数据库还是数据提交过程中?
maosenmin 2009-08-29
  • 打赏
  • 举报
回复
你全换成GBK,页面,struts.xml文件里那个i18n,包括你的开发平台。最后就是把Tomcat里的conf\service.xml里也添加一个东西, <Connector port="8080" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="GBK" /> 这个后面加上URIEncoding="GBK" ,只要在你IE访问的那个端口的Connector后加就可以了.当然还有你数据库本身的编码。这个要看你什么数据库了。
fengxiaowenhappy 2009-08-29
  • 打赏
  • 举报
回复
我没有在页面内部导入页面啊
zhaoyunrui 2009-08-29
  • 打赏
  • 举报
回复
有一种可能,在页面内部导入页面时,页面的编码尽量使gbk的...
xiaochengfu1 2009-08-29
  • 打赏
  • 举报
回复
自己写个过滤器试试,跟数据库也有关系
TeBieChi 2009-08-29
  • 打赏
  • 举报
回复
重写 actionservlet
或者自己写一个过滤器

81,092

社区成员

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

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