encodeURIComponent

来源:互联网 发布:虚拟机运行mac os x慢 编辑:程序博客网 时间:2024/04/30 11:56

encodeURIComponent

<script type="text/javascript">  function show(){       var f="#wer中文测试";       f = encodeURIComponent(encodeURIComponent(f));       test.value = f;        var url = "servlet/Test?f="+f;        var rtv = showModalDialog(url,"","dialogWidth:820px; dialogHeight:620px; status:0;help:0;scrolling:auto");    }  </script>  <body><input id="test" value="">   <input type="button" value="TEST" onclick="show()" />   </body>

package com.yourcompany.struts.action;import java.io.UnsupportedEncodingException;import java.net.URLDecoder;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import com.yourcompany.struts.form.TestForm;public class TestAction extends Action {    public ActionForward execute(ActionMapping mapping, ActionForm form,            HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {        TestForm testForm = (TestForm) form;                response.setCharacterEncoding("UTF-8");        String name=testForm.getName();        String pwd=testForm.getPwd();                response.setCharacterEncoding("UTF-8");        String myname=request.getParameter("myname");        myname=URLDecoder.decode(myname, "UTF-8");        String mypwd=request.getParameter("mypwd");        mypwd=URLDecoder.decode(mypwd, "UTF-8");                System.out.println(name);        System.out.println(pwd);        System.out.println(myname);        System.out.println(mypwd);                request.setAttribute("name", name);        request.setAttribute("pwd", pwd);        request.setAttribute("myname", myname);        request.setAttribute("mypwd", mypwd);                return mapping.findForward("go");    }}


0 0
原创粉丝点击