struts2中form提交到action中的中文參數(shù)亂碼問題解決辦法(包括取中文路徑)
我的前臺(tái)頁(yè)是這樣的:
<body>
<form action="test.action" method="post">
測(cè)試文件:<input type="file" id="doc" name="path" value=""/>
<input type="submit" value="提交" onclick=""/>
</form>
</body>
Action:
package com;

import java.io.UnsupportedEncodingException;


import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class TestAction extends ActionSupport
{
private String path;

public String getPath()
{
return path;
}

public void setPath(String path)
{
this.path = path;
}


public String test() throws Exception
{
System.out.println(path.replace("\\", "\\\\"));
return SUCCESS;
}

}
剛開始的時(shí)候一選中文路徑就輸出???.
后來終于找到解決方法.
在struts.xml文件中加上:
為了解決form提交到action中的中文參數(shù)亂碼問題。
1.在struts2-core-2.0.0-SNAPSHOT.jar包中路徑為struts2-core-2.0.6\org\apache \struts2
有一個(gè)default.properties 文件,把struts.i18n.encoding=UTF-8改為
struts.i18n.encoding=GBK
2.或者在struts.xml文件內(nèi)添加常量:
<constant name="struts.i18n.encoding" value="GBK"/>
我當(dāng)然是用的第二種方法,簡(jiǎn)單方便.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.i18n.encoding" value="GBK"/>
<package name="com" extends="struts-default">
<action name="test" class="com.TestAction" method="test">
<result>/ok.jsp</result>
</action>
</package>
</struts>
呵呵,終于解決了.希望對(duì)大家有些幫助.





































剛開始的時(shí)候一選中文路徑就輸出???.
后來終于找到解決方法.
在struts.xml文件中加上:
為了解決form提交到action中的中文參數(shù)亂碼問題。
1.在struts2-core-2.0.0-SNAPSHOT.jar包中路徑為struts2-core-2.0.6\org\apache \struts2
有一個(gè)default.properties 文件,把struts.i18n.encoding=UTF-8改為

2.或者在struts.xml文件內(nèi)添加常量:

我當(dāng)然是用的第二種方法,簡(jiǎn)單方便.













呵呵,終于解決了.希望對(duì)大家有些幫助.
posted on 2007-12-26 12:24 々上善若水々 閱讀(12705) 評(píng)論(5) 編輯 收藏 所屬分類: Struts2