环境:两个服务器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());
}
%>
实现功能:使用两个服务器实现图片上传,一个服务器负责上传界面显示,另一个服务器负责后台上传实现,然后把图片地址传给服务器一显示图片
问题: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());
}
%>
解决方案 »
- 求助啊!struts和网页框架集的问题
- 用dwr,要把bean集合传递给页面
- 前辈们.. 如果你也有过这样的痛苦.. 请你进来帮帮我..
- NullPointerException问题
- struts从数据库中读取文件存在服务器上的一个问题,应用服务器使用tomcat
- struts中使用javascript的问题!急
- Spring2.0.1项目jsp页面显示空白。。。
- <求助>Json传值问题
- java InterestClient Exception in thread "main" java.lang.NoClassDefFoundError: InterestClient 这个异常为什么?在线等!!
- 请推荐java XML解析器,有经验的分析一下不同!谢谢!
- 使用javabean+Dao类+一个index的jsp页面,从数据库里查询几行数据显示到浏览器index页面上
- freemaker 枚举 比较
<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>
我随便写两个页面测试的时候都可以取到hidden里的值,为什么我写图片上传跨服务器跨项目时却取不到了
如果在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组件,其他上传下载组件应该也可以,希望以后遇到这类问题的朋友可以得到解决。 谢谢各位的回答了