jsp页面的javascript代码: 
function change(parm){ 
 ..
 var  path ="你好";
}
这个页面通过struts2跳转,请问在action中如何获取path这个字符串?请给出思路及代码,谢谢!

解决方案 »

  1.   

    var path ="你好";1. url
    document.forms[0].action = "xxx.action?path=" + encodeURI(encodeURI(path));
    document.forms[0].submit();
    action
    request.getParameter("path");
    2. set val into form hidden;
    document.getElementById("path").value = path;
    <input type="hidden" value="" id="path" />action
    private String path;setter/getter;
      

  2.   


    String path = request.getParameter("path");
    path = java.net.URLDecoder.decode(path, "UTF-8"); 
      

  3.   

    你这段javascript代码应该要在页面跳转之前执行
    代码中把这变量设置到request
    这样后台才能获取到数据
      

  4.   

    我继续解答吧,这次只能贴代码了
    <s:file name="uploadPic" id="upload" onchange="loadPath()"/>
    <s:hidden name="uploadPath" id="path"/>//用来传递上传文件本地路径
    function loadPath()
    {
        //通过ID获取文件域的文件名(包括路径)
        var filePath=document.getElementById("upload").value;    //将文件名(包括路径)赋予隐藏域
        document.getElementById("path").value=filePath;
        alert(filePath);
    }
    以上代码不兼容FIREFOX
      

  5.   

    上面的JS代码不兼容IE8和FIREFOX,重新发过可以兼容的JS代码function getFilePath(obj)   
    {   
      if(obj)   
       {   
        if (window.navigator.userAgent.indexOf("MSIE")>=1)   
         {   
           obj.select();   
           return document.selection.createRange().text;   
         }   
        else if(window.navigator.userAgent.indexOf("Firefox")>=1)   
         {   
          if(obj.files)   
           {   
            return obj.files.item(0).getAsDataURL();   
           }   
          return obj.value;   
         }   
        return obj.value;   
       }   
    }     function loadPath()
    {
        //通过ID获取文件域的文件名(包括路径)
    var obj=document.getElementById("upload");
        var filePath=getFilePath(obj);    //将文件名(包括路径)赋予隐藏域
        document.getElementById("path").value=filePath;
        alert(filePath);
    }
      

  6.   

    通过url传参或放大隐藏域中。
      

  7.   

    javascript中:
    var path = "yourPath";
    location.href="yourAction.action?path="+path;Action中:
    String path = request.getParameter("path");
      

  8.   

    最简单url里传过去,后台这样取参数就行了。String param= request.getParameter("param");
      

  9.   

    var path ="你好";1. url
    document.forms[0].action = "xxx.action?path=" + encodeURI(encodeURI(path));
    document.forms[0].submit();
    action
    request.getParameter("path");
    2. set val into form hidden;
    document.getElementById("path").value = path;
    <input type="hidden" value="" id="path" />action
    private String path;setter/getter;、答案了