读书人

关于透过url传参的编码转化

发布时间: 2012-09-10 22:20:12 作者: rapoo

关于通过url传参的编码转化
1.action中先把参数转化成UTF-8的编码格式:

public class HelloWorldAction {private String msg;private String userName;public String getUserName() {return userName;}public String getMessage1() {return msg;}public String execute() throws Exception{ActionSupport xxx;userName = URLEncoder.encode("参数", "UTF-8");msg = "我的第一个struts2应用";return "success";}}

2.struts.xml中配置url传参:
<action name="redirectTestAndparam" ><result type="redirect">/employeeAdd1.jsp?userName=${userName}</result>        </action>

3.jsp页面中得到参数(ISO8859-1),并转成UTF-8的字符串
<%= new String(request.getParameter("userName").getBytes("ISO8859-1"),"UTF-8") %>

读书人网 >Web前端

热点推荐