`
- 浏览:
40158 次
-
BaseAction
-
packagecom.easyjob.cnhuike.actions;
-
importjavax.servlet.ServletContext;
-
importjavax.servlet.http.HttpServletRequest;
-
importjavax.servlet.http.HttpServletResponse;
-
importjavax.servlet.http.HttpSession;
-
importorg.apache.struts2.ServletActionContext;
-
importorg.springframework.context.ApplicationContext;
-
importjava.io.*;
-
importjava.util.ArrayList;
-
importjava.util.List;
-
importcom.easyjob.cnhuike.util.modelConstant.LoginConstant;
-
importcom.framework.util.DateUtil;
-
importcom.opensymphony.xwork2.ActionSupport;
-
-
publicclassBaseActionextendsActionSupport{
-
-
publicstaticfinalStringLIST="list";
-
publicstaticfinalStringNEXT="next";
-
StringinputAction;
-
StringnextAction;
-
-
-
publicHttpServletRequestgetRequest(){
-
returnServletActionContext.getRequest();
-
}
-
-
publicHttpServletResponsegetResponse(){
-
returnServletActionContext.getResponse();
-
}
-
-
publicHttpSessiongetSession(){
-
returngetRequest().getSession();
-
}
-
-
publicServletContextgetServletContext(){
-
returnServletActionContext.getServletContext();
-
}
-
-
publicStringgetRealyPath(Stringpath){
-
returngetServletContext().getRealPath(path);
-
}
-
-
-
publicStringgetInputAction(){
-
returninputAction;
-
}
-
publicvoidsetInputAction(StringinputAction){
-
this.inputAction=inputAction;
-
}
-
publicStringgetNextAction(){
-
returnnextAction;
-
}
-
publicvoidsetNextAction(StringnextAction){
-
this.nextAction=nextAction;
-
}
-
}
上传用的BaseAction
-
packagecom.easyjob.cnhuike.actions;
-
-
-
importjava.io.BufferedInputStream;
-
importjava.io.BufferedOutputStream;
-
importjava.io.File;
-
importjava.io.FileInputStream;
-
importjava.io.FileOutputStream;
-
importjava.io.IOException;
-
importjava.io.InputStream;
-
importjava.io.OutputStream;
-
importjava.util.ArrayList;
-
importjava.util.List;
-
-
importcom.framework.util.DateUtil;
-
-
publicclassBaseUploadFileActionextendsBaseAction{
-
publicstaticfinalintBUFFER_SIZE=16*1024;
-
-
publicFile[]upload;
-
-
publicString[]uploadFileName;
-
-
publicString[]uploadContentType;
-
-
publicStringsavePath="";
-
-
publicBaseUploadFileAction(){
-
savePath="\\uploadFile";
-
}
-
-
-
publicbooleancopy(Filesrc,Filedst,intBUFFER_SIZE){
-
booleanresult=false;
-
InputStreamin=null;
-
OutputStreamout=null;
-
try{
-
in=newBufferedInputStream(newFileInputStream(src),BUFFER_SIZE);
-
out=newBufferedOutputStream(newFileOutputStream(dst),
-
BUFFER_SIZE);
-
byte[]buffer=newbyte[BUFFER_SIZE];
-
intlen=0;
-
while((len=in.read(buffer))>0){
-
out.write(buffer,0,len);
-
}
-
result=true;
-
}catch(Exceptione){
-
e.printStackTrace();
-
result=false;
-
}finally{
-
if(null!=in){
-
try{
-
in.close();
-
}catch(IOExceptione){
-
e.printStackTrace();
-
}
-
}
-
if(null!=out){
-
try{
-
out.close();
-
}catch(IOExceptione){
-
e.printStackTrace();
-
}
-
}
-
}
-
returnresult;
-
}
-
-
-
-
publicList<String>uploadFile(Stringpath,booleanisFullPath)throwsIOException{
-
List<String>successFileList=newArrayList<String>();
-
-
for(inti=0;i<upload.length;i++){
-
-
StringsrcFilesInfo=uploadFileName[i].toString();
-
-
StringFileExtensions=srcFilesInfo.substring(srcFilesInfo.lastIndexOf("."),srcFilesInfo.length());
-
StringfileName=DateUtil.getNowDate(null)+"-"+DateUtil.getHour()+DateUtil.getMinute()+DateUtil.getSecond()+i+FileExtensions;
-
StringdstPath=getRealyPath(path)+"\\"+fileName;
-
FiledstFile=newFile(dstPath);
-
if(copy(upload[i],dstFile,BUFFER_SIZE)){
-
if(isFullPath){
-
successFileList.add(path+fileName);
-
}else{
-
successFileList.add(fileName);
-
}
-
}
-
if(successFileList.size()<1){
-
thrownewIOException();
-
}
-
}
-
returnsuccessFileList;
-
}
-
-
publicList<String>uploadFile(Stringpath)throwsIOException{
-
returnuploadFile(path,false);
-
}
-
-
-
publicList<String>getFileNames(Stringpath){
-
Filefile=newFile(getRealyPath(path));
-
List<String>resultList=newArrayList<String>();
-
File[]files=file.listFiles();
-
for(FiletempFile:files){
-
if(tempFile.isFile()){
-
resultList.add(tempFile.getName());
-
}
-
}
-
returnresultList;
-
}
-
-
-
publicvoidcreateFold(Stringpath){
-
try{
-
path=getRealyPath(path);
-
Filefolder=newFile(path);
-
if(!folder.exists()){
-
folder.mkdirs();
-
}
-
-
}catch(Exceptione){
-
e.printStackTrace();
-
}
-
}
-
-
-
-
-
-
publicFile[]getUpload(){
-
returnupload;
-
}
-
-
publicvoidsetUpload(File[]upload){
-
this.upload=upload;
-
}
-
-
publicString[]getUploadFileName(){
-
returnuploadFileName;
-
}
-
-
publicvoidsetUploadFileName(String[]uploadFileName){
-
this.uploadFileName=uploadFileName;
-
}
-
-
publicString[]getUploadContentType(){
-
returnuploadContentType;
-
}
-
-
publicvoidsetUploadContentType(String[]uploadContentType){
-
this.uploadContentType=uploadContentType;
-
}
-
-
publicStringgetSavePath(){
-
returnsavePath;
-
}
-
-
publicvoidsetSavePath(StringsavePath){
-
this.savePath=savePath;
-
}
-
-
publicstaticintgetBUFFER_SIZE(){
-
returnBUFFER_SIZE;
-
}
-
}
上传时所用到的拦截配置
-
<interceptors>
-
<interceptor-stackname="albumUpload">
-
<interceptor-refname="fileUpload">
-
<!--配置允许上传的文件类型,多个用","分隔-->
-
<paramname="allowedTypes">
-
image/bmp,image/png,image/gif,image/jpeg,image/jpg,image/x-png,image/pjpeg
-
</param>
-
<!--配置允许上传的文件大小,单位字节-->
-
<paramname="maximumSize">10240000</param>
-
</interceptor-ref>
-
<interceptor-refname="defaultStack"/>
-
</interceptor-stack>
-
</interceptors>
-
-
<actionname="album!*"class="com.easyjob.cnhuike.actions.AlbumAction"method="{1}">
-
<interceptor-refname="albumUpload"/>
-
<result>/album/album_{1}.jsp</result>
-
<resultname="list"type="redirect-action">album!{1}List</result>
-
<resultname="error">/album/album_error.jsp</result>
-
<resultname="input">/album/album_error.jsp</result>
-
<resultname="next"type="redirect-action">
-
<paramname="actionName">${nextAction}</param>
-
<paramname="namespace">/album</param>
-
</result>
-
</action>
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
有关BaseAction,DispatchAction,XXXAction的一个小测试工程,希望对刚接触BaseAction的人有用
很好用的工具类,希望帮助到大家
utils类及baseAction 非常详细哦
action的超类 其他类的继承它,里面有详细说明
具体实现 我现在的程序是基于ThinkPHP框架的,我们会有一个父类控制器,下面我就把这个设置cookie的代码加到这个BaseAction里面的_initialize()函数中,这样程序就大大简化工作量了。 复制代码 代码如下:$refer = ...
在web层和dao层都提取了公共代码封装到BaseAction和BaseDao中,提高了代码的复用,同时按照OO设计原则,针对接口编程,而不是针对实现编程。 使用拦截器的方法对系统权限进行初步控制(后续可以采用Shiro框架进行...
因此,在对本系统进行架构设计的时候,考虑建立一个抽象的BaseAction类,该类继承LookupDispatchAction,实现LookupDispatchAction类中的getKeyMethodMap方法,在方法中返回本系统中请求参数值与资源文件中参数值的...
在web层和dao层都提取了公共代码封装到BaseAction和BaseDao中,提高了代码的复用性,同时遵循OO设计原则,接口是针对编程的,而不是针对实现编程的。 使用拦截器的方法对系统权限进行初步控制(后续可以采用Shiro...
中间业务层是通过Spring框架实现的,首先建立一个 BaseAction,它继承了Action类,而其他定义的Action都要继承这个BaseAction。这个B aseAction需要导入AppContext工具类,这个AppContext需要导入Spring中 ;这样一个...
jQuery EasyUI与Struts2 的整合—属性驱动篇 如果你是用模型驱动,或者是直接把属性写在action里面,你不会...BaseAction.java ApproveAction.java approveList.jsp jQuery EasyUI与Struts2 的整合—属性驱动篇.docx
************************************************************************************* ...运行成功后输入 http://localhost:8080/MySSH1.0/baseAction!tologin.action 如果数据库中插入数据表明整合成功!
public class SupplierSort_Action extends BaseAction implements ModelDriven<SupplierSort>{ //调用数据访问层 SupplierSort supplierSort = new SupplierSort(); public SupplierSort getModel(){ return ...
public class BaseAction extends DispatchAction { public FdlUserService fus; public FdmShisanhachuService chus; public FdlMachineService mas; public FdlTenkaService tens; public FdmShisanService ...
..........\...\..\..\......\BaseAction.java ..........\...\..\..\dao\XiangmubiaoDAO.java ..........\...\..\..\persist\Xiangmubiao.hbm.xml ..........\...\..\..\.......\Xiangmubiao.java ..........\...
该类必须继承com.hikvision.swdf.xx.BaseAction<{EntityName}>,该Action类有一个关键属性entity,即泛型Entity类的一个实体,该属性默认填充好了请求提交过来的entity对应参数(即entity.propertyName);...
public class CarriageBidQueryAction extends BaseAction { protected ActionForward execute(BActionContext context) throws Exception { System.out.println("------- CarriageBidQueryAction execute...
简单的ssh项目,泛型BaseAction配置,简单注解配置,applicationContext.xml配置,jar包地址 链接:https://pan.baidu.com/s/14NkywuhG6mESyhE1VMkhOQ 密码:en19
包含WEB开发的Servlet,Struts2等开发所需的构架文件,底层的BaseAction,JDBC等底层封装