struts1和struts2的區別,struts2中處理get請求亂碼

 2023-11-18 阅读 20 评论 0

摘要:struts2對于表單提交進行了攔截和編碼,而且也可以通過filter來統一進行表單編碼轉換 但是對于get請求所帶的參數為中文,struts2就無能為力了 在網上查找了一些方法,但都不行 這就需要我們自己來處理 首先把原來的鏈接: struts1和struts2的區別?&

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");
????}

重新編碼后就不會出現亂碼了

轉載于:https://www.cnblogs.com/qixing/archive/2013/05/14/get%e4%b9%b1%e7%a0%81.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/2/175554.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息