SSH Sprong配置 Action 中应用的接口,bean中配置class属性应为Action中国你调用接口的实现类:
例如:
接口:
//----------------------------------
package com.action.service;
import java.io.IOException;
import java.util.List;
public interface WorkService {
public void WorkZipService(String newpath,String cid,String urlfilename,String zipname,String zippwd) throws Exception ;
public boolean WorkMapCopyService(String oldpath,List<String> sattachmentname,String newp,String cid,List<String> nname) throws Exception;
}
//--------------------------------
接口实现类:
//--------------------------------------
package com.action.serviceimpl;
import java.io.IOException;
import java.util.List;
import com.action.service.WorkService;
import com.bean.Sattachment;
import com.dao.SattachmentDAO;
import com.util.OneUtil;
import com.util.ThreeUtil;
import com.util.TwoUtil;
public class WorkServiceImple implements WorkService {
private SattachmentDAO sattachmentDAO;
public SattachmentDAO getSattachmentDAO() {
return sattachmentDAO;
}
public void setSattachmentDAO(SattachmentDAO sattachmentDAO) {
this.sattachmentDAO = sattachmentDAO;
}
public void WorkZipService(String newpath,String cid, String urlfilename,
String zipname,String zippwd) throws Exception {
// TODO Auto-generated method stub
String pathcid=newpath+"\\"+cid.trim()+"\\";
new ThreeUtil().creatTex(pathcid.trim()+"\\"+urlfilename,pathcid);//pathcid,urlfilename,
new TwoUtil().encryptZip(pathcid,newpath+"\\"+zipname,zippwd);
}
public boolean WorkMapCopyService(String oldpath,
List<String> sattachmentname, String newp, String cid,
List<String> nname) throws Exception {
System.out.println("WorkMapCopyService ");
OneUtil oneutil=new OneUtil();
boolean sn=oneutil.checkMapBeforueZip(oldpath);
System.out.println("checkMapBeforueZip "+sn);
if(sn)
{
if(nname!=null && nname.size()>0)
{
for(int j=0;j<nname.size();j++)
{
List<Sattachment> listsattachment=sattachmentDAO.findAllByNodeName(nname.get(j));
if(listsattachment!=null && listsattachment.size()>0)
{
for(int k=0;k<listsattachment.size();k++)
{
Sattachment sattachment=listsattachment.get(k);
System.out.println("sattachment.getName() "+sattachment.getName());
if(sattachment.getName()!=null && !sattachment.getName().equals(""))
{
sattachmentname.add(sattachment.getName());
}
}
}
}
}
oneutil.copyMap(sattachmentname,oldpath, newp, cid);
return true;
}
return false;
}
}
//---------------------------------------
Action:
//-------------------------------------------
package com.action;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.action.service.WorkService;
import com.bean.Node;
import com.bean.Sattachment;
import com.dao.CourseDAO;
import com.dao.NodeDAO;
import com.dao.SattachmentDAO;
import com.opensymphony.xwork2.ActionSupport;
import com.util.OneUtil;
import com.util.ThreeUtil;
import com.util.TwoUtil;
public class WorkAction extends ActionSupport {
private WorkService workService;
public WorkService getWorkService() {
return workService;
}
public void setWorkService(WorkService workService) {
this.workService = workService;
}
public String workCrouse() throws IOException {
HttpServletRequest request = ServletActionContext.getRequest();
OneUtil oneutil = new OneUtil();
String cid = request.getParameter("cid");
String oldpath = request.getRealPath("Uploadfiles");
String newp = request.getRealPath("czip");
List<Node> node = new ArrayList<Node>();
List<String> nid = new ArrayList<String>();
List<String> nname = new ArrayList<String>();
List<String> sattachmentname=new ArrayList<String>();
String msg="";
boolean sign=true;
if(workService.WorkCheckStr(cid))
{
try
{
node = workService.WorkGetNodeByCid(cid);
for (int i = 0; i < node.size(); i++) {
Node n = node.get(i);
if (n.getCourseid() != null) {
nid.add(n.getId().toString());
if(n.getName()!=null && !n.getName().equals(""))
{
nname.add(n.getName().trim());
}
}
}
sign = workService.WorkCheckCid(newp, cid);
if (sign) {
workService.WorkeCopyCouseMesgge(oldpath, newp, cid, nid);
workService.WorkMapCopyService(oldpath, sattachmentname, newp, cid, nname);
sign = workService.WorkCheckCidBeforueZip(newp,cid);
if(sign)
{
workService.WorkZipService(newp,cid.trim(), "url.txt", cid.trim()+".zip", "12345");
msg="压缩成功!";
}else
{
msg="该课程没有资源信息!";
}
}
else
{
workService.WorkCreaCidFoloder(newp, cid);
workService.WorkeCopyCouseMesgge(oldpath, newp, cid, nid);
workService.WorkMapCopyService(oldpath, sattachmentname, newp, cid, nname);
sign = workService.WorkCheckCidBeforueZip(newp,cid);
if(sign)
{
workService.WorkZipService(newp,cid.trim(), "url.txt", cid.trim()+".zip", "12345");
msg="压缩成功!";
}
else
{
msg="该课程没有资源信息!";
}
}
}
catch(Exception e)
{
msg="该课程没有章节信息!";
node=new ArrayList<Node>();
}
}
else
{
msg="传入参数错误!";
}
request.setAttribute("msg",msg);
return SUCCESS;
}
}
//----------------------------------------
spring xml:
//-------------------------------------------
<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
............................省略
<bean id="SattachmentDAO" class="com.dao.SattachmentDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="WorkService" class="com.action.serviceimpl.WorkServiceImple">
<property name="sattachmentDAO">
<ref bean="SattachmentDAO"/>
</property>
</bean>
<bean id="workAction" class="com.action.WorkAction">
<property name="workService">
<ref bean="WorkService"/>
</property>
</bean>
</beans>
//-------------------------------------------