环境:两个服务器A和B,两个java应用程序A负责传参B负责接收参数,A应用程序在A服务器上,B应用程序在B服务器上
实现功能:使用两个服务器实现图片上传,一个服务器负责上传界面显示,另一个服务器负责后台上传实现,然后把图片地址传给服务器一显示图片
问题:B服务器中的应用程序B通过request.getParameter("htmlEditorBasePath")取不到值
具体代码:
        应用程序A重要代码:
     <body>
        <form action="http://192.168.0.67:80/htmlEditor/showImage/upload4htmleditor.jsp" method="post"      enctype="multipart/form-data" name="upformHtmlEditor1" >
          <input type="hidden" name="forwardPath" value="/yysHtmlEditor/showPicture?htmlId=HtmlEditor1">
          <input type="hidden" name="htmlEditorBasePath" value="http://localhost:8082/lnyhxs/">
          <input type="hidden" name="htmlId" value="HtmlEditor1">
          <input type="hidden" name="uploadedFileProcessor" value="yys.htmleditor.PictureProcessor" />
          <input name="file" id="file" type="file" class="input" />
          <input type="hidden" name="dateFormat" value="">
          <input type="hidden" name="uploadPath" value="temp">
          <input name="Submit" type="submit" class="button" value="上传" />
      </form>
    </body>
        B服务器上应用程序B重要代码:
<%
SmartUpload mySmartUpload =new SmartUpload();
long file_size_max=4000000;
String fileName2="",ext="",testvar="";
String url="updateImage/"; 
String htmlEditorBasePath=request.getParameter("htmlEditorBasePath"); //问题所在,取不到值
String htmlId=request.getParameter("htmlId");   //问题所在,取不到值
mySmartUpload.initialize(pageContext);
try {mySmartUpload.setAllowedFilesList("jpg,gif,JPG,GIF");//此处的文件格式可以根据需要自己修改//上载文件mySmartUpload.upload();} catch (Exception e){
e.printStackTrace();
%><SCRIPT language=javascript>alert("只允许上传.jpg和.gif类型图片文件");window.history.go(-1);</script><%}try{com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(0);if (myFile.isMissing()){%><SCRIPT language=javascript>alert("请先选择要上传的文件");
window.history.go(-1);
</script>
<%}
else{
//String myFileName=myFile.getFileName(); ext= myFile.getFileExt(); int file_size=myFile.getSize(); String saveurl="";if(file_size<file_size_max){Calendar calendar = Calendar.getInstance();String filename = String.valueOf(calendar.getTimeInMillis());Date dt =new Date();SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM");    String strTime=sdf.format(dt)+"/";saveurl=application.getRealPath("/")+url+strTime;File file =new File(saveurl);if(!file.exists()){ file.mkdir();}
saveurl+=filename+"."+ext; myFile.saveAs(saveurl,SmartUpload.SAVE_PHYSICAL);  String httpUrl=url+strTime+filename+"."+ext;%>
 <html>
 <head>
  <title>图片</title>
  <a href=URL target="image"></a>
 </head>
 <body onload="load();">
  <form name="form1" method="post" action="<%=htmlEditorBasePath %>/yysHtmlEditor/showPicture">
  <input name="uploadUrl" type="hidden" value="http://192.168.0.67/htmlEditor/<%=httpUrl%>">
  <input name="htmlId" type="hidden" value="<%=htmlId %>">
  </form>
 </body>
 <script>
  function load(){    
    document.form1.submit();
  }
 </script>
</html>
<%
}
}
}catch (Exception e){
out.print(e.toString());
}
%>

解决方案 »

  1.   

    问题就是我用request.getParameter("htmlEditorBasePath")取不到值,取的值是Null
      

  2.   

    仅仅是hidden了,没有传递过去参数。。
      

  3.   

    request不是空,两个hidden参数都没有传递过来,如果form标签里使用get方法时,可以获取到两个hidden的值,但是request.getContentLength()的值就为-1了,所以我必须用Post方法传递
      

  4.   

    我不能用这种方法传参,这种方法可以取到值,但是由于我action里的值是通过取web.xml配置文件里的一个属性值得到的,我所贴出来的应用程序A是JAR包里的文件编译后的结果,JAR包里的源码是:
    <body>
    <form action="${uploadService}" method="${uploadMethod}" enctype="multipart/form-data" name="upform${htmlId}" onSubmit="return checkform${htmlId}();">
    <input type="hidden" name="forwardPath" value="${upfile}?htmlId=${htmlId}">
    <input type="hidden" name="htmlEditorBasePath" value="${basePath}">
    <input type="hidden" name="htmlId" value="${htmlId}">
    <input type="hidden" name="uploadedFileProcessor" value="yys.htmleditor.PictureProcessor" />
    <input name="file" id="file" type="file" class="input" />
    <input type="hidden" name="dateFormat" value="${dateFormat}">
    <input type="hidden" name="uploadPath" value="${uploadPath}">
    <input name="Submit" type="submit" class="button" value="上传" />
    </form>
    </body>
      

  5.   

    没人知道吗?????
    我随便写两个页面测试的时候都可以取到hidden里的值,为什么我写图片上传跨服务器跨项目时却取不到了
      

  6.   

    http://192.168.0.67:80/htmlEditor/showImage/upload4htmleditor.jsp   这个地址是B服务器的地址么?
      

  7.   

    你取不到值和hidden有关系么 ? 难道你把hidden写成text 就能取到值了?
      

  8.   

    谢谢各位的帮助,问题已经解决了,这个问题搞了我两天,以后大家也可能会遇到这个问题。
    如果在jsp页面的表单form中指定ENCTYPE= "multipart/form-data ",意思是form中的信息已流的方式传递,那么后台通过request.getParameter()获取参数是获取不到的,返回总是null。
    要想在后台获取参数,就需要使用第三方组件jsmartupload,
    SmartUpload su = new SmartUpload();     
    su.initialize(pageContext);     
    su.upload();     
    String s = su.getRequest().getParameter( "ID "); //接受前一个页面的值  
    一定要把取参数的放在upload()方法之后,否则取出的值依然是null。
    smartupload只是一个文件上传下载的java组件,其他上传下载组件应该也可以,希望以后遇到这类问题的朋友可以得到解决。 谢谢各位的回答了