sturt2乱码问题,网上的答案还是解决不了,谢谢大家帮忙
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中的中文字段显示乱码。