struts2基本应用于配置(持续更新...)

  1. struts.xml中的一些常见配置:

<!-- 该属性指定需要Struts2处理的请求后缀,该属性的默认值是action,即所有匹配*.action的请求都由Struts2处理。
如果用户需要指定多个请求后缀,则多个后缀之间以英文逗号(,)隔开。 -->
<constant name="struts.action.extension" value="do" />
<!-- 设置浏览器是否缓存静态内容,默认值为true(生产环境下使用),开发阶段最好关闭 -->
<constant name="struts.serve.static.browserCache" value="false" />
<!-- 当struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false(生产环境下使用),开发阶段最好打开 -->
<constant name="struts.configuration.xml.reload" value="true" />
<!-- 开发模式下使用,这样可以打印出更详细的错误信息 -->
<constant name="struts.devMode" value="true" />
<!-- 默认的视图主题 -->
<constant name="struts.ui.theme" value="simple" />
<!--<constant name="struts.objectFactory" value="spring" />-->
<!--解决乱码 -->
<constant name="struts.i18n.encoding" value="UTF-8" />
<!-- 指定允许上传的文件最大字节数。默认值是2097152(2M) -->
<constant name="struts.multipart.maxSize" value="10701096"/>
<!-- 设置上传文件的临时文件夹,默认使用javax.servlet.context.tempdir -->
<constant name="struts.multipart.saveDir " value="d:/tmp" />

2.   struts2的上传:使用FileUtils

jsp写法

文件上传测试:

         <form action="${pageContext.request.contextPath }/user_upload.action"

                  enctype="multipart/form-data" method="post">

         <input type="file" name="upFile">

         <input type="submit" value="上传">

         </form>

action写法:

private File upFile;

         private String upFileFileName;

         private String upFileContentType;

public String upload() throws IOException{

                  File saveFile=new File(ServletActionContext.getServletContext().getRealPath("/images"));

                  org.apache.commons.io.FileUtils.copyFile(upFile, new File(saveFile,upFileFileName));

                  return "success";

         }

 

你可能感兴趣的:(struts2基本应用于配置(持续更新...))