?? documentaction.java
字號:
request.setAttribute("BASELIST",l);
}catch(Exception e){
generalError(request,e);
return mapping.findForward("failure");
}
return mapping.findForward("list1");
}
//得到別人派發(fā) 派發(fā)的合同
public ActionForward listFinish(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response){
try{
HttpSession session = request.getSession();
String username = (String)session.getAttribute("username");
// int status = Integer.parseInt(request.getParameter("status"));
int offset;
int length=PAGE_LENGTH;
String pageOffset=request.getParameter("pager.offset");
if(pageOffset==null||pageOffset.equals("")){
offset=0;
}else{
offset=Integer.parseInt(pageOffset);
}
String url=request.getContextPath()+mapping.getPath()+".do?action=listFinish";
List list = getDocumentManager().findDocumentListFinish(offset,length,username);
List list2 = getDocumentManager().poVO(list);
int size = getDocumentManager().getAllDocumentNumFinish(username);
String pagerHeader=PagerUtil.generate(offset,size,length,url);
request.setAttribute("pagerHeader",pagerHeader);
request.setAttribute("BASELIST",list2);
}catch(Exception e){
generalError(request,e);
return mapping.findForward("failure");
}
return mapping.findForward("listFinish");
}
public ActionForward update(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response){
/*
try{
Document doc = new Document();
doc.setId(request.getParameter("id"));
doc.setStatus(1);
documentManager.update(doc);
}catch(Exception e){
generalError(request,e);
return mapping.findForward("failure");
}*/
try{
HttpSession session = request.getSession();
String beginUser = (String)session.getAttribute("username");
// 當(dāng)上傳文件超過限制時設(shè)定的臨時文件位置
String tempPath = "C:\\TEMP";
// 設(shè)置最多只允許在內(nèi)存中存儲的數(shù)據(jù),單位:字節(jié)
//private int sizeThreshold = 4096;
int sizeThreshold = 4096000;
// 設(shè)置允許用戶上傳文件大小,單位:字節(jié)
// 共10M
long sizeMax = 10*10485760;
Document doc = new Document(); //提交文檔用
String documentName = request.getParameter("documentName");
log.info(documentName);
String filePath = request.getSession().getServletContext().getRealPath("/uploadFiles");
File d = new File(filePath);
if(d.exists()){
}else{
d.mkdir();
}
DiskFileUpload fu = new DiskFileUpload();
/*
if (request.getCharacterEncoding() == null) {
fu.setHeaderEncoding("UTF-8");
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
} else {
*/
fu.setHeaderEncoding("GBK");
// System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+request.getCharacterEncoding());
//}
// 設(shè)置最多只允許在內(nèi)存中存儲的數(shù)據(jù),單位:字節(jié)
fu.setSizeThreshold(sizeThreshold);
// 設(shè)置允許用戶上傳文件大小,單位:字節(jié)
// 10M
fu.setSizeMax(sizeMax);
fu.setRepositoryPath(tempPath);
//開始讀取上傳信息
Iterator iter = null;
// 讀取上傳信息
try {
List fileItems = fu.parseRequest(request);
// 處理上傳項目
// 依次處理每個上傳的文件
iter = fileItems.iterator();
} catch (FileUploadException e) {
log.info("上傳文件過大");
//e.printStackTrace();
log.info(e.getMessage());
}
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
// 忽略其他不是文件域的所有表單信息
if (!item.isFormField()) {
// 上傳的是文件信息
//String fieldName = item.getFieldName();
String name = item.getName();
if((name == null) || name.equals("") && item.getSize() == 0){
continue;
}
String fileName = this.GetFileName(name);
// fileName = new String(fileName.getBytes("ISO8859_1"),"utf-8");
setFileName(System.currentTimeMillis()+"-"+fileName);
try {
//FileOutputStream fos = new FileOutputStream(new File(this.destinationPath + fileName));
FileOutputStream fos = new FileOutputStream(new File(filePath +"/"+ getFileName() ));
InputStream uploadStream = item.getInputStream();
BufferedInputStream bis = new BufferedInputStream(uploadStream);
byte b[] = new byte[sizeThreshold];
int nRead;
while( (nRead = bis.read(b,0,sizeThreshold)) >0){
fos.write(b, 0, nRead);
}
uploadStream.close();
bis.close();
fos.close();
} catch (Exception e) {
//e.printStackTrace();
log.info(e.getMessage());
}
}else{
// 上傳的是普通表單字域
String fieldName = item.getFieldName();
String name = item.getName();
//System.out.println(fieldName);
if(fieldName.equals("documentName")){
doc.setName(item.getString());
}
if(fieldName.equals("confirmName")){
doc.setEndUser(item.getString());
}
if(fieldName.equals("docID")){
doc.setId(item.getString());
}
if((name == null) || name.equals("") && item.getSize() == 0){
continue;
}
}
}
doc.setBeginUser(beginUser);
doc.setFilename(fileName);
//doc.setUsername(request.getParameter("confirmName"));
doc.setStatus(1);
documentManager.update(doc);
}catch(Exception e){
generalError(request,e);
return mapping.findForward("failure");
}
//return new ActionForward("documentManager.do?action=listDo",true);
return new ActionForward("documentManager.do?action=listFinish",true);
}
public ActionForward edit(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response){
try{
}catch(Exception e){
generalError(request,e);
return mapping.findForward("failure");
}
return mapping.findForward("main");
}
public ActionForward status(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response){
try{
String docID = request.getParameter("docID");
List list = getDocumentManager().findDocumentListStatus(docID);//.findDocumentListFinish(offset,length,username);
List l = getDocumentManager().nodeVO(list);
request.setAttribute("BASELIST",l);
}catch(Exception e){
generalError(request,e);
return mapping.findForward("failure");
}
return mapping.findForward("status");
}
public String GetFileName(String filepath)
{
String returnstr = "*.*";
int length = filepath.trim().length();
filepath = filepath.replace('\\', '/');
if(length >0)
{
int i = filepath.lastIndexOf("/");
if (i >= 0)
{
filepath = filepath.substring(i + 1);
returnstr = filepath;
}
}
return returnstr;
}
String fileName;
public String getFileName(){
return fileName;
}
public void setFileName(String fileName){
this.fileName = fileName;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -