当前位置: 代码迷 >> Java Web开发 >> 求下传的高手,
  详细解决方案

求下传的高手,

热度:6872   发布时间:2013-02-25 21:07:59.0
求上传的高手,在线等啊
 我的页面是一个 
 <input type="file" name="file"  id="file">
      <br>
      <input type="text" align="top"  style="width: 300px;height:300px;background-color: white"  > 

我选择好文件以后 要马上把文件的内容读到文本框里面 
   读写的方法已经写好了
       这个怎么连起来  

------最佳解决方案--------------------------------------------------------
读写的方法写在服务器端的话,就直接用ajax来传输数据
没有经过封装最原始的:
<script language="JavaScript" type="text/javascript">
var xmlHttp = false;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
}else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function strParse(){
createXMLHttpRequest();
xmlHttp.onreadystatechange = callback;
xmlHttp.open("post","test.action",true);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
xmlHttp.send(null);
function callback(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
var data = xmlHttp.responseText;
var spNode = document.getElementById("file");
spNode.innerHTML = data;
}
}else{
 document.getElementById("file").innerHTML="正在读取...";
}
}

}
</script>
服务器端只要这么输出:
PrintWriter out = response.getWriter();
out.print(".....");
------其他解决方案--------------------------------------------------------
自己顶顶
------其他解决方案--------------------------------------------------------
通过form表单去获取,事件触发后将值写入。
------其他解决方案--------------------------------------------------------
struts1:FormFile封装

  FileUpForm upForm=(FileUpForm)form;
  FormFile formFile=upForm.getMyFile();
  InputStream in=formFile.getInputStream();

struts2:File封装
------其他解决方案--------------------------------------------------------
要显示的页面放一个控件,传上去之后通过
window.opener.form1.jjpic.value = 'value';
的方式可以将值跨页面传过去
------其他解决方案--------------------------------------------------------
null
  相关解决方案