现在我只想用file做上传 后台也是自定义问题是:
1.点击按钮提交到后台 ,后带如何能获取到这个附件,前端如何做(带文件的表单提交如果设置,后台应该接受的是一个文件流)现在我是直接将地址传到后代(这样做是有问题,无法获取文件),要怎么才能设置成流的形式
2.后代方法参数没有流类型的,只有 8种基本数据类型和 xml,map,object等,接受文件流设置成啥?
说白了,就是基于平台做个基本的文件上传,因为我不需要上传到服务器,只读出来解析而已,所以没考虑用att,我查了资料,都没有说明白怎么去做,请帮忙解决,谢谢。
前台如下:<?xml version="1.0" encoding="UTF-8"?>
<div xmlns="http://www.w3.org/1999/xhtml" xid="window" class="window" component="$UI/system/components/justep/window/window" design="device:pc"> <div component="$UI/system/components/justep/model/model" xid="model1" style="position:absolute;top:168px;left:318px;height:auto;"></div><div component="$UI/system/components/justep/model/model" xid="model" style="height:auto;top:39px;left:314px;"/> <div component="$UI/system/components/justep/panel/panel" class="x-panel x-full" xid="panel1"> <div class="x-panel-top" xid="top1"></div> <div class="x-panel-content" xid="content1"><div class="form-horizontal container-fluid" component="$UI/system/components/bootstrap/form/form" xid="form1"><input type="file" value="" xid="onlyWordFile"></input> <a component="$UI/system/components/justep/button/button" class="btn btn-default" label="确定" xid="button1" onClick="button1Click"> <i xid="i1"></i> <span xid="span1">确定</span></a></div></div> <div class="x-panel-bottom" xid="bottom1"></div></div></div>
js代码如下:
define(function(require){ var $ = require("jquery"); var justep = require("$UI/system/lib/justep"); var biz = require("$UI/system/lib/biz"); var Model = function(){ this.callParent(); };
Model.prototype.button1Click = function(event){ biz.Request.sendBizRequest({ "context" : this.getContext(), "action" : "newAction_0", "parameters" : { "path" : this.getElementByXid("onlyWordFile").value }, "callback" : function(data) { data.ignoreError = false; if (data.state) { justep.Util.hint("动作调用成功!"); } } });
};
return Model;
});
java 代码如下: import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.math.*; import java.sql.*; import java.util.*;
import org.apache.poi.POIXMLDocument; import org.apache.poi.POIXMLTextExtractor; import org.apache.poi.hwpf.extractor.WordExtractor; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.xwpf.extractor.XWPFWordExtractor; import org.dom4j.*;
import com.justep.system.data.*;
public class OnlyWrold {
public static String newAction_0(String path){ String buffer = ""; try { if (path.endsWith(".doc")) { InputStream is = new FileInputStream(new File(path)); WordExtractor ex = new WordExtractor(is); buffer = ex.getText(); } else if (path.endsWith("docx")) { OPCPackage opcPackage = POIXMLDocument.openPackage(path); POIXMLTextExtractor extractor = new XWPFWordExtractor(opcPackage); buffer = extractor.getText(); } else { System.out.println("此文件不是word文件!"); }
} catch (Exception e) { e.printStackTrace(); }
return buffer; }
}
|