struts2的配置

1。struts.xml文档

 

 

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
 <constant name="struts.action.exension" value="do,action" />
 <!-- struts_2的配置 -->
 <package name="test" extends="struts-default">
  <!-- action中的name属性的第一个星星代表的是action的名字,
  第二个星星代表的是action类中的方法名字 -->
  <action name="*_*" class="{1}action" method="{2}">
   <result name="ok">/fileMain.jsp</result>
   <result name="no">/index.jsp</result>
  </action>
 </package>
</struts>

 

2。AddFileAction.java文件代码

 

package com.tsinghua.six.myoffices.document.struts2.action;

import java.io.File;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.opensymphony.xwork2.ActionSupport;

import com.tsinghua.six.myoffices.pojo.FileinfoSix;
import com.tsinghua.six.myoffices.pojo.FiletypeinfoSix;
import com.tsinghua.six.myoffices.services.document.servif.DocumentBiz;

public class AddFileAction extends ActionSupport implements Serializable {

 /**
  * 增加文件夹 action date:2010-10-13-10:25
  * Date date = time.parse(random);//把时间从String转换为Date类型
  */

 private static final long serialVersionUID = 1L;

 private int fileid; // 文件ID

 private FiletypeinfoSix filetypeinfoSix; // 文件类型(FileTypeInfo表的外键,对应FileTypeId字段)

 private String filename; // 文件名称

 private String remark; // 文件备注

 private String fileowner; // 创建者

 private String createdate; // 创建日期

 private int parentid; // 父节点ID(可能是树形下拉菜单所要用到的查询值)

 private String filepath; // 文件路径

 private int ifdelete; // 判断是否已经删除(1:表未删除,0:表已删除)

 private DocumentBiz documentBiz ;//文件夹方法代理
 
 private FileinfoSix FileinfoSixbean ;//文件夹封装Bean
 
 public void setFileinfoSixbean(FileinfoSix fileinfoSixbean) {
  FileinfoSixbean = fileinfoSixbean;
 }

 public void setDocumentBiz(DocumentBiz documentBiz) {
  this.documentBiz = documentBiz;
 }

 public int getFileid() {
  return fileid;
 }

 public void setFileid(int fileid) {
  this.fileid = fileid;
 }

 public FiletypeinfoSix getFiletypeinfoSix() {
  return filetypeinfoSix;
 }

 public void setFiletypeinfoSix(FiletypeinfoSix filetypeinfoSix) {
  this.filetypeinfoSix = filetypeinfoSix;
 }

 public String getFilename() {
  return filename;
 }

 public void setFilename(String filename) {
  this.filename = filename;
 }

 public String getRemark() {
  return remark;
 }

 public void setRemark(String remark) {
  this.remark = remark;
 }

 public String getFileowner() {
  return fileowner;
 }

 public void setFileowner(String fileowner) {
  this.fileowner = fileowner;
 }

 public String getCreatedate() {
  return createdate;
 }

 public void setCreatedate(String createdate) {
  this.createdate = createdate;
 }

 public int getParentid() {
  return parentid;
 }

 public void setParentid(int parentid) {
  this.parentid = parentid;
 }

 public String getFilepath() {
  return filepath;
 }

 public void setFilepath(String filepath) {
  this.filepath = filepath;
 }

 public int getIfdelete() {
  return ifdelete;
 }

 public void setIfdelete(int ifdelete) {
  this.ifdelete = ifdelete;
 }
 //struts.xml文档中的action的name属性第二个星星代表的是这个方法的名字
 public String addFile() throws Exception {
  System.out.println("文件夾名字:" + filename);
  System.out.println("创建时间:" + createdate);
  System.out.println("文件夹路径:" + filepath);
  System.out.println("创建者:" + fileowner);
  System.out.println("备注:" + remark);

  try {
   // 创建文件夹
   String path = this.filepath + "/" + this.filename;
   File file = new File(path);

   // 判断是否有该文件夹
   if (!file.exists()) {
    // 新创建文件夹
    file.mkdirs();
   }
//   // 转化时间
//   SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd/HH:mm:ss");
//   Date date = time.parse(this.createdate);
//   System.out.println("=============Date格式以后=======:"+date);
   //时间
   System.out.println("时间:"+this.createdate);
   FileinfoSixbean.setCreatedate(createdate);
   //文件夹路径
   FileinfoSixbean.setFilepath(path);
   //文件夹名称
   FileinfoSixbean.setFilename(filename);
   //文件夹备注
   FileinfoSixbean.setRemark(remark);
   //创建者
   FileinfoSixbean.setFileowner(fileowner);
   //是否删除
   FileinfoSixbean.setIfdelete(1);
   //父节点
   FileinfoSixbean.setParentid(parentid);
   //文件夹类型
   FileinfoSixbean.setFiletypeinfoSix(null);
   System.out.println("到此处!");
   boolean insert = documentBiz.addInsert(FileinfoSixbean);
   if(insert){
    System.out.println("文件夹信息增加正常!");
    return "ok" ;
   }
  } catch (Exception e) {
   System.out.println("===============文件夹增加信息action出现异常!");
   e.getMessage();
   e.printStackTrace();
  }
  return "no" ;
 }

}

 

3。applicationContext-action.xml   注入spring的struts2

 

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

 <!-- 专门配置action -->

 <bean name="addFileInsertaction"
  class="com.tsinghua.six.myoffices.document.struts2.action.AddFileAction">
  <property name="fileinfoSixbean" ref="FileinfoSix" />
  <property name="documentBiz" ref="DocumentBizImpl" />
 </bean>

<!--   filePropertyaction分开为filePropery和action,filePropery代表的是struts.xml文档第一个星星的值,

action代表的是struts.xml文档第二个星星的值 -->
 <bean name="filePropertyaction" class="com.tsinghua.six.myoffices.document.struts2.action.FilePropertyAction">
  
 </bean>

</beans> 

 

 

注释:最近郁闷的很,不知道怎么把项目源码上传至博客中来保存,如果如果整个工程都发布上来,既麻烦,又费时,请问有哪位侠客知否??如知,请告诉于我,在此谢谢!

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值