struts2對于表單提交進行了攔截和編碼,而且也可以通過filter來統一進行表單編碼轉換
但是對于get請求所帶的參數為中文,struts2就無能為力了
在網上查找了一些方法,但都不行
這就需要我們自己來處理
首先把原來的鏈接:
struts1和struts2的區別?<a href="${pageContext.request.contextPath }/manage/reportManage_reportProfit.action?page=${request.profit.totalPage}&searchType=${searchType}&searchContent=${searchContent">下一頁</a>
修改成js觸發形式:
<a href="javascript:next('${request.profit.totalPage}&','${searchType}','${searchContent}');">下一頁</a>
js:
function next(page,searchType,searchContent){
?window.location.href="${pageContext.request.contextPath }/manage/reportManage_reportDaily.action?page="+page+"&searchType="+searchType+"&method=get&searchContent="+encodeURI(searchContent);
}
通過js來把searchContent編碼,這樣在Action中接受到的編碼是iso-8859-1的形式
java.lang.string cannot be cast。在Action中把字符串的編碼格式轉換為utf-8;
if(method!=null&&method.equals("get")){
?????searchContent= new String(searchContent.getBytes("iso-8859-1"),"utf-8");
????}
重新編碼后就不會出現亂碼了