当前位置: 代码迷 >> Web前端 >> 关于透过url传参的编码转化
  详细解决方案

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

热度:69   发布时间:2012-09-10 22:20:12.0
关于通过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" class="cn.itcast.action.HelloWorldAction" >
			<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") %>

  相关解决方案