- 浏览: 31254 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
wgx198302:
现在在项目中,人员水平不一,用起来容易会出错。
struts2标签实际大全 -
aaronhugo:
我们最近做项目用的就是Struts2,我用了蛮多的标签,str ...
struts2标签实际大全
该文件上传实现可以限制上传文件的类型,限制上传文件的最大字节数,上传文件既可以存储在相对路径下,也可以存储在绝对路径下。
一、Model类源代码
Java代码
public class Attachments {
private long id;
private String name; //文件名
private String path; //上传文件存放的子目录路径
private Long fileSize; //文件大小,单位为K
private String contentType; //文件类型
private String refName = "attachment"; //引用名称,默认为attachment,可用于区分普通附件与特殊附件。
private String entityName; //指定与附件关联的表单的实体名称
private String entityId; //指定与附件关联的表单的主键值
private String creator; //创建人
private Timestamp createDate; //创建时间
private File attachFile; //待上传的文件对象
......
}
public class Attachments {
private long id;
private String name; //文件名
private String path; //上传文件存放的子目录路径
private Long fileSize; //文件大小,单位为K
private String contentType; //文件类型
private String refName = "attachment"; //引用名称,默认为attachment,可用于区分普通附件与特殊附件。
private String entityName; //指定与附件关联的表单的实体名称
private String entityId; //指定与附件关联的表单的主键值
private String creator; //创建人
private Timestamp createDate; //创建时间
private File attachFile; //待上传的文件对象
......
}
二、Action类源代码
Java代码
public class UploadAction extends BaseAction {
private UploadService uploadService;
private Attachments attach;
//限制
private String allowTypes = "";
private long maxSize = 0; //字节
//上传的文件
private File upload;
private String uploadFileName;
private String uploadContentType;
......
//获取与表单关联的所有附件信息
public String attachList() throws Exception{
List attachList = uploadService.queryAttachments(attach);
getValueStack().set("attachList", attachList);
return SUCCESS;
}
//上传附件
public String upload() throws Exception{
String method = getRequest().getMethod();
if(method.equalsIgnoreCase("post")){
if(upload != null){
if(upload.length() <= 0){
throw new RuntimeException("上传的文件不能为空!");
}
if(maxSize > 0 && upload.length() > maxSize){
throw new RuntimeException("上传的文件不能超过" + maxSize + "字节!");
}
allowTypes = CommonUtil.trim(allowTypes);
if(CommonUtil.isNotEmpty(allowTypes)){
int idx = uploadFileName.lastIndexOf(".");
String extendName = uploadFileName.substring(idx+1); //扩展名
List typesList = CommonUtil.toList(allowTypes, ",");
if(!typesList.contains(extendName)){
throw new RuntimeException("只能上传扩展名为[ " + allowTypes + " ]的文件!");
}
}
attach.setAttachFile(upload);
attach.setName(uploadFileName);
attach.setFileSize(new Long(upload.length() / 1024)); //K
attach.setContentType(uploadContentType);
attach.setCreator(SecurityUtil.getUserId());
attach.setCreateDate(DatetimeUtil.nowTimestamp());
uploadService.addAttachment(attach);
}else{
return INPUT;
}
}else{
return INPUT;
}
return SUCCESS;
}
//删除附件
public String attachDelete() throws Exception{
Map map = RequestUtil.getParameterMap(getRequest(), "chk_o_");
uploadService.deleteAttachment(map);
StringBuffer sb = new StringBuffer();
sb.append("attachList.action?attach.entityName=" + CommonUtil.trim(attach.getEntityName()));
sb.append("&attach.entityId=" + CommonUtil.trim(attach.getEntityId()));
sb.append("&attach.refName=" + CommonUtil.trim(attach.getRefName()));
sb.append("&attach.path=" + CommonUtil.trim(attach.getPath()));
sb.append("&allowTypes=" + CommonUtil.trim(allowTypes));
sb.append("&maxSize=" + maxSize);
getValueStack().set("url", sb.toString());
return SUCCESS;
}
//下载附件
public String download() throws Exception{
return SUCCESS;
}
public InputStream getTargetFile() throws Exception{
attach = uploadService.getAttachment(attach.getId());
uploadFileName = URLEncoder.encode(attach.getName(), "UTF-8"); //解决中文乱码问题
String filePath = attach.getPath();
if(filePath.indexOf(":") == -1){ //相对路径
return ServletActionContext.getServletContext().getResourceAsStream(filePath);
}else{ //绝对路径
return new FileInputStream(filePath);
}
}
}
public class UploadAction extends BaseAction {
private UploadService uploadService;
private Attachments attach;
//限制
private String allowTypes = "";
private long maxSize = 0; //字节
//上传的文件
private File upload;
private String uploadFileName;
private String uploadContentType;
......
//获取与表单关联的所有附件信息
public String attachList() throws Exception{
List attachList = uploadService.queryAttachments(attach);
getValueStack().set("attachList", attachList);
return SUCCESS;
}
//上传附件
public String upload() throws Exception{
String method = getRequest().getMethod();
if(method.equalsIgnoreCase("post")){
if(upload != null){
if(upload.length() <= 0){
throw new RuntimeException("上传的文件不能为空!");
}
if(maxSize > 0 && upload.length() > maxSize){
throw new RuntimeException("上传的文件不能超过" + maxSize + "字节!");
}
allowTypes = CommonUtil.trim(allowTypes);
if(CommonUtil.isNotEmpty(allowTypes)){
int idx = uploadFileName.lastIndexOf(".");
String extendName = uploadFileName.substring(idx+1); //扩展名
List typesList = CommonUtil.toList(allowTypes, ",");
if(!typesList.contains(extendName)){
throw new RuntimeException("只能上传扩展名为[ " + allowTypes + " ]的文件!");
}
}
attach.setAttachFile(upload);
attach.setName(uploadFileName);
attach.setFileSize(new Long(upload.length() / 1024)); //K
attach.setContentType(uploadContentType);
attach.setCreator(SecurityUtil.getUserId());
attach.setCreateDate(DatetimeUtil.nowTimestamp());
uploadService.addAttachment(attach);
}else{
return INPUT;
}
}else{
return INPUT;
}
return SUCCESS;
}
//删除附件
public String attachDelete() throws Exception{
Map map = RequestUtil.getParameterMap(getRequest(), "chk_o_");
uploadService.deleteAttachment(map);
StringBuffer sb = new StringBuffer();
sb.append("attachList.action?attach.entityName=" + CommonUtil.trim(attach.getEntityName()));
sb.append("&attach.entityId=" + CommonUtil.trim(attach.getEntityId()));
sb.append("&attach.refName=" + CommonUtil.trim(attach.getRefName()));
sb.append("&attach.path=" + CommonUtil.trim(attach.getPath()));
sb.append("&allowTypes=" + CommonUtil.trim(allowTypes));
sb.append("&maxSize=" + maxSize);
getValueStack().set("url", sb.toString());
return SUCCESS;
}
//下载附件
public String download() throws Exception{
return SUCCESS;
}
public InputStream getTargetFile() throws Exception{
attach = uploadService.getAttachment(attach.getId());
uploadFileName = URLEncoder.encode(attach.getName(), "UTF-8"); //解决中文乱码问题
String filePath = attach.getPath();
if(filePath.indexOf(":") == -1){ //相对路径
return ServletActionContext.getServletContext().getResourceAsStream(filePath);
}else{ //绝对路径
return new FileInputStream(filePath);
}
}
}
三、Service类源代码
Java代码
public class UploadService extends BaseService {
/**
* 保存附件信息并将附件文件存储到指定目录下
*/
public void addAttachment(Attachments attach)throws Exception{
if(CommonUtil.isEmpty(attach.getRefName())) attach.setRefName("attachment");
//文件存储基路径
String path = CommonUtil.trim(attach.getPath());
if(CommonUtil.isNotEmpty(path)){
if(path.endsWith("/") == false && path.endsWith("\\") == false){
path += File.separator;
}
if(path.startsWith("/")==false && path.startsWith("\\")==false){
if(Constants.attachBasePath.endsWith("/")==false && Constants.attachBasePath.endsWith("\\")==false){
path = File.separator + path;
}
}
}
path = Constants.attachBasePath + path;
attach.setPath(path);
save(attach);
//文件存储路径
if(path.endsWith("/") == false && path.endsWith("\\") == false){
path += File.separator;
}
path += attach.getId() + "_o_" + attach.getName();
attach.setPath(path);
update(attach);
//目标文件
String filePath = path;
if(filePath.indexOf(":") == -1) filePath = ServletActionContext.getRequest().getRealPath(filePath); //不是绝对路径就转成绝对路径
File dstFile = new File(filePath);
FileUtil.createPath(dstFile.getParent()); //目标目录不存在时创建
//文件保存
try{
FileUtil.copyFile(attach.getAttachFile(), dstFile);
}catch(FileNotFoundException ex){
throw new ServiceException("文件不存在:" + attach.getName());
}
}
/**
* 删除选中的附件信息及其对应的文件
*/
public void deleteAttachment(Map map) throws ServiceException{
List pathList = new ArrayList();
for(Iterator it=map.keySet().iterator();it.hasNext();){
String key = (String)it.next();
String value = (String)map.get(key);
Attachments attach = (Attachments)load(Attachments.class, new Long(value));
if(attach != null){
pathList.add(attach.getPath());
delete(attach);
}
}
for(int i=0;i<pathList.size();i++){
String filePath = (String)pathList.get(i);
if(filePath.indexOf(":") == -1){
filePath = ServletActionContext.getRequest().getRealPath(filePath);
}
File file = new File(filePath);
FileUtil.deleteFile(file);
}
}
/**
* 查找附件
*/
public List queryAttachments(Attachments attach)throws Exception{
DetachedCriteria dc = DetachedCriteria.forClass(Attachments.class);
CriteriaUtil.eq(dc, "entityName", attach.getEntityName());
CriteriaUtil.eq(dc, "entityId", attach.getEntityId());
CriteriaUtil.eq(dc, "refName", attach.getRefName());
dc.addOrder(Order.asc("createDate"));
return findByCriteria(dc);
}
public Attachments getAttachment(long id)throws Exception{
return (Attachments)load(Attachments.class, new Long(id));
}
}
一、Model类源代码
Java代码
public class Attachments {
private long id;
private String name; //文件名
private String path; //上传文件存放的子目录路径
private Long fileSize; //文件大小,单位为K
private String contentType; //文件类型
private String refName = "attachment"; //引用名称,默认为attachment,可用于区分普通附件与特殊附件。
private String entityName; //指定与附件关联的表单的实体名称
private String entityId; //指定与附件关联的表单的主键值
private String creator; //创建人
private Timestamp createDate; //创建时间
private File attachFile; //待上传的文件对象
......
}
public class Attachments {
private long id;
private String name; //文件名
private String path; //上传文件存放的子目录路径
private Long fileSize; //文件大小,单位为K
private String contentType; //文件类型
private String refName = "attachment"; //引用名称,默认为attachment,可用于区分普通附件与特殊附件。
private String entityName; //指定与附件关联的表单的实体名称
private String entityId; //指定与附件关联的表单的主键值
private String creator; //创建人
private Timestamp createDate; //创建时间
private File attachFile; //待上传的文件对象
......
}
二、Action类源代码
Java代码
public class UploadAction extends BaseAction {
private UploadService uploadService;
private Attachments attach;
//限制
private String allowTypes = "";
private long maxSize = 0; //字节
//上传的文件
private File upload;
private String uploadFileName;
private String uploadContentType;
......
//获取与表单关联的所有附件信息
public String attachList() throws Exception{
List attachList = uploadService.queryAttachments(attach);
getValueStack().set("attachList", attachList);
return SUCCESS;
}
//上传附件
public String upload() throws Exception{
String method = getRequest().getMethod();
if(method.equalsIgnoreCase("post")){
if(upload != null){
if(upload.length() <= 0){
throw new RuntimeException("上传的文件不能为空!");
}
if(maxSize > 0 && upload.length() > maxSize){
throw new RuntimeException("上传的文件不能超过" + maxSize + "字节!");
}
allowTypes = CommonUtil.trim(allowTypes);
if(CommonUtil.isNotEmpty(allowTypes)){
int idx = uploadFileName.lastIndexOf(".");
String extendName = uploadFileName.substring(idx+1); //扩展名
List typesList = CommonUtil.toList(allowTypes, ",");
if(!typesList.contains(extendName)){
throw new RuntimeException("只能上传扩展名为[ " + allowTypes + " ]的文件!");
}
}
attach.setAttachFile(upload);
attach.setName(uploadFileName);
attach.setFileSize(new Long(upload.length() / 1024)); //K
attach.setContentType(uploadContentType);
attach.setCreator(SecurityUtil.getUserId());
attach.setCreateDate(DatetimeUtil.nowTimestamp());
uploadService.addAttachment(attach);
}else{
return INPUT;
}
}else{
return INPUT;
}
return SUCCESS;
}
//删除附件
public String attachDelete() throws Exception{
Map map = RequestUtil.getParameterMap(getRequest(), "chk_o_");
uploadService.deleteAttachment(map);
StringBuffer sb = new StringBuffer();
sb.append("attachList.action?attach.entityName=" + CommonUtil.trim(attach.getEntityName()));
sb.append("&attach.entityId=" + CommonUtil.trim(attach.getEntityId()));
sb.append("&attach.refName=" + CommonUtil.trim(attach.getRefName()));
sb.append("&attach.path=" + CommonUtil.trim(attach.getPath()));
sb.append("&allowTypes=" + CommonUtil.trim(allowTypes));
sb.append("&maxSize=" + maxSize);
getValueStack().set("url", sb.toString());
return SUCCESS;
}
//下载附件
public String download() throws Exception{
return SUCCESS;
}
public InputStream getTargetFile() throws Exception{
attach = uploadService.getAttachment(attach.getId());
uploadFileName = URLEncoder.encode(attach.getName(), "UTF-8"); //解决中文乱码问题
String filePath = attach.getPath();
if(filePath.indexOf(":") == -1){ //相对路径
return ServletActionContext.getServletContext().getResourceAsStream(filePath);
}else{ //绝对路径
return new FileInputStream(filePath);
}
}
}
public class UploadAction extends BaseAction {
private UploadService uploadService;
private Attachments attach;
//限制
private String allowTypes = "";
private long maxSize = 0; //字节
//上传的文件
private File upload;
private String uploadFileName;
private String uploadContentType;
......
//获取与表单关联的所有附件信息
public String attachList() throws Exception{
List attachList = uploadService.queryAttachments(attach);
getValueStack().set("attachList", attachList);
return SUCCESS;
}
//上传附件
public String upload() throws Exception{
String method = getRequest().getMethod();
if(method.equalsIgnoreCase("post")){
if(upload != null){
if(upload.length() <= 0){
throw new RuntimeException("上传的文件不能为空!");
}
if(maxSize > 0 && upload.length() > maxSize){
throw new RuntimeException("上传的文件不能超过" + maxSize + "字节!");
}
allowTypes = CommonUtil.trim(allowTypes);
if(CommonUtil.isNotEmpty(allowTypes)){
int idx = uploadFileName.lastIndexOf(".");
String extendName = uploadFileName.substring(idx+1); //扩展名
List typesList = CommonUtil.toList(allowTypes, ",");
if(!typesList.contains(extendName)){
throw new RuntimeException("只能上传扩展名为[ " + allowTypes + " ]的文件!");
}
}
attach.setAttachFile(upload);
attach.setName(uploadFileName);
attach.setFileSize(new Long(upload.length() / 1024)); //K
attach.setContentType(uploadContentType);
attach.setCreator(SecurityUtil.getUserId());
attach.setCreateDate(DatetimeUtil.nowTimestamp());
uploadService.addAttachment(attach);
}else{
return INPUT;
}
}else{
return INPUT;
}
return SUCCESS;
}
//删除附件
public String attachDelete() throws Exception{
Map map = RequestUtil.getParameterMap(getRequest(), "chk_o_");
uploadService.deleteAttachment(map);
StringBuffer sb = new StringBuffer();
sb.append("attachList.action?attach.entityName=" + CommonUtil.trim(attach.getEntityName()));
sb.append("&attach.entityId=" + CommonUtil.trim(attach.getEntityId()));
sb.append("&attach.refName=" + CommonUtil.trim(attach.getRefName()));
sb.append("&attach.path=" + CommonUtil.trim(attach.getPath()));
sb.append("&allowTypes=" + CommonUtil.trim(allowTypes));
sb.append("&maxSize=" + maxSize);
getValueStack().set("url", sb.toString());
return SUCCESS;
}
//下载附件
public String download() throws Exception{
return SUCCESS;
}
public InputStream getTargetFile() throws Exception{
attach = uploadService.getAttachment(attach.getId());
uploadFileName = URLEncoder.encode(attach.getName(), "UTF-8"); //解决中文乱码问题
String filePath = attach.getPath();
if(filePath.indexOf(":") == -1){ //相对路径
return ServletActionContext.getServletContext().getResourceAsStream(filePath);
}else{ //绝对路径
return new FileInputStream(filePath);
}
}
}
三、Service类源代码
Java代码
public class UploadService extends BaseService {
/**
* 保存附件信息并将附件文件存储到指定目录下
*/
public void addAttachment(Attachments attach)throws Exception{
if(CommonUtil.isEmpty(attach.getRefName())) attach.setRefName("attachment");
//文件存储基路径
String path = CommonUtil.trim(attach.getPath());
if(CommonUtil.isNotEmpty(path)){
if(path.endsWith("/") == false && path.endsWith("\\") == false){
path += File.separator;
}
if(path.startsWith("/")==false && path.startsWith("\\")==false){
if(Constants.attachBasePath.endsWith("/")==false && Constants.attachBasePath.endsWith("\\")==false){
path = File.separator + path;
}
}
}
path = Constants.attachBasePath + path;
attach.setPath(path);
save(attach);
//文件存储路径
if(path.endsWith("/") == false && path.endsWith("\\") == false){
path += File.separator;
}
path += attach.getId() + "_o_" + attach.getName();
attach.setPath(path);
update(attach);
//目标文件
String filePath = path;
if(filePath.indexOf(":") == -1) filePath = ServletActionContext.getRequest().getRealPath(filePath); //不是绝对路径就转成绝对路径
File dstFile = new File(filePath);
FileUtil.createPath(dstFile.getParent()); //目标目录不存在时创建
//文件保存
try{
FileUtil.copyFile(attach.getAttachFile(), dstFile);
}catch(FileNotFoundException ex){
throw new ServiceException("文件不存在:" + attach.getName());
}
}
/**
* 删除选中的附件信息及其对应的文件
*/
public void deleteAttachment(Map map) throws ServiceException{
List pathList = new ArrayList();
for(Iterator it=map.keySet().iterator();it.hasNext();){
String key = (String)it.next();
String value = (String)map.get(key);
Attachments attach = (Attachments)load(Attachments.class, new Long(value));
if(attach != null){
pathList.add(attach.getPath());
delete(attach);
}
}
for(int i=0;i<pathList.size();i++){
String filePath = (String)pathList.get(i);
if(filePath.indexOf(":") == -1){
filePath = ServletActionContext.getRequest().getRealPath(filePath);
}
File file = new File(filePath);
FileUtil.deleteFile(file);
}
}
/**
* 查找附件
*/
public List queryAttachments(Attachments attach)throws Exception{
DetachedCriteria dc = DetachedCriteria.forClass(Attachments.class);
CriteriaUtil.eq(dc, "entityName", attach.getEntityName());
CriteriaUtil.eq(dc, "entityId", attach.getEntityId());
CriteriaUtil.eq(dc, "refName", attach.getRefName());
dc.addOrder(Order.asc("createDate"));
return findByCriteria(dc);
}
public Attachments getAttachment(long id)throws Exception{
return (Attachments)load(Attachments.class, new Long(id));
}
}
发表评论
-
struts2 的国际化支持
2010-05-13 16:26 1250struts2 的国际化支持 文章分类:Java编程 关键字: ... -
Struts2 <s:token/>标签<转>
2010-05-13 16:12 1377Struts2 <s:token/>标签 转自“h ... -
struts2.0升级到struts2.1.6遇到的问题汇总
2009-10-12 21:02 1312问题一 web.xml的变化 struts2.1中的写法为: ... -
struts2.0 与struts2.1.x 的区别
2009-10-12 21:01 2270每次struts的更新,都会发生它的基础jar包不同,下面我就 ... -
struts2标签实际大全
2009-08-21 13:48 1239(1):<s:textfield> ---- ... -
struts2标签说明
2009-08-21 13:23 1300一、iterator. 这个标签 ... -
Struts1和Struts2的区别和对比(转)
2009-08-06 17:48 5771.Action 类: • Struts1要求Action类 ...
相关推荐
本书《Struts2技术内幕——深入解析Struts2架构设计与实现原理》结合提供的《struts2基础.chm》资料,为我们提供了深入理解Struts2内部机制的机会。 首先,Struts2的核心在于它的拦截器(Interceptor)机制。拦截器...
总的来说,这个基于Struts2的班级网站项目涵盖了Struts2框架的多个关键方面,对于初学者来说,这是一个很好的实践平台,可以深入理解MVC架构、Action、拦截器、结果类型、文件上传以及用户状态管理等核心概念。...
标题 "ssh2(struts2+spring2.5+hibernate3.3+ajax)带进度条文件上传(封装成标签)" 涉及到的是一个基于Java Web的项目,利用了Struts2、Spring2.5、Hibernate3.3和Ajax技术,实现了文件上传并带有进度条显示的功能...
9. **commons-fileupload-1.3.jar**:Apache Commons FileUpload库专门处理HTTP请求中的多部分文件上传,Struts2使用它来支持用户上传文件的功能。 10. **commons-logging-1.1.3.jar**:Apache Commons Logging是...
总的来说,要实现Java Struts2框架下上传jad等文件类型,我们需要配置Struts2的文件上传支持,编写处理文件上传的Action类,以及可能需要解析和处理jad文件的额外逻辑。以上各步骤都需要对Struts2框架、文件上传机制...
4. **Interceptor拦截器**:Struts2的拦截器可以用来实现通用的文件上传和下载逻辑,例如限制上传大小,记录日志等。 5. **安全性**:文件上传可能导致安全问题,如代码注入、跨站脚本攻击(XSS)。因此,确保对...
6. `Commons-fileupload`:处理HTTP多部分文件上传的库,通常与Struts2一起使用。 在集成第三方框架时,比如Spring,需要额外引入如`struts2-spring-plugin-2.x.x.jar`这样的插件JAR文件。 Struts2的启动配置与...
Struts2是一个强大的Java EE(Enterprise Edition)框架,主要用于构建基于MVC(Model-View-Controller)模式的Web应用程序。这个框架提供了丰富的功能,包括动作调度、数据绑定、异常处理、国际化支持等,大大简化...
4. **文件上传API**:在Struts2中,通常使用`CommonsFileUpload`库来处理文件上传。这个库提供了`FileItem`接口,可以获取上传文件的信息,并将其保存到服务器的指定位置。 5. **安全注意事项**: - **防止文件...
struts2必须包,commons-fileupload-1.3.1.jar 实现文件上传包,commons-io-2.2.jar 用来处理IO的一些工具类包,commons-lang3-3.1.jar 提供一些基础的、通用的操作和处理,如自动生成toString()的结果、自动实现...
文件上传是Web应用中常见的一项功能,Struts2提供了简单易用的方式来实现这一需求。 ##### 4.3 高级表单处理技巧 在表单处理方面,Struts2支持多种高级技巧,如自动填充表单字段、动态生成表单元素等。 ##### 4.4...
- **拦截器**:Struts2的核心之一,通过拦截器可以实现诸如文件上传、输入验证等功能。 - **处理与分配流程**: - **前端请求**:用户发起的HTTP请求。 - **StrutsPrepareAndExecuteFilter**:处理请求的第一道...
Struts2提供了许多内置的Interceptor,它们覆盖了常见的Web应用程序需求,如参数绑定、类型转换、输入验证、文件上传等。这些内置的Interceptor可以帮助开发者快速构建功能丰富的应用程序,而无需从头开始实现这些...
2. **文件上传下载**:展示了如何使用Struts2处理文件上传和下载,包括文件大小限制、类型检查等。 3. **拦截器实战**:通过自定义拦截器,可以实现如登录检查、权限控制等功能。 4. **Ajax支持**:Struts2提供了对...
这些JAR文件是构建基于Struts2的应用的基础,缺少任何一个都可能导致应用无法正常运行。以下是对这些核心组件的详细介绍: 1. **.struts2-core.jar**:这是Struts2框架的核心库,包含Action、Result、Interceptor等...
### Struts2框架基础知识 #### 一、Struts2框架简介 Struts2是一个基于Java的开源Web应用程序...此外,Struts2还提供了丰富的特性支持,如表单验证、文件上传、AJAX支持等,使得开发者能够构建更为复杂的应用程序。
在开发基于Struts2的应用时,正确配置和选用所需的资源包至关重要,这能确保项目的稳定性和高效性。在这个“配置struts2需要的资源包”的主题中,我们将详细探讨Struts2的核心组件、依赖库以及如何精简不必要的包。 ...
2. **依赖的Apache Commons库**:Struts2依赖于Apache Commons家族的多个库,如Commons FileUpload用于文件上传,Commons Logging用于日志记录,Commons Lang用于提供通用的Java语言工具等。 3. **插件库**:Struts...
拦截器是Struts2的一大特色,可以实现如日志、权限检查、事务管理等通用功能,并且可以按需组合使用。结果类型则是决定Action执行完成后如何跳转到视图页面。 Struts2的Action支持多种结果类型,包括JSP、...