Struts2 随笔1
配置拦截器 <interceptors><interceptor-stack name="mystack"><!-- 默认的拦截器 --><interceptor-ref name="struts-default"></interceptor-ref><!--查看每个运行action时间 --><interceptor-ref name="timer"></interceptor-ref></interceptor-stack></interceptors><!-- 修改默认拦截器(要在action之前) --><default-interceptor-ref name="mystack"></default-interceptor-ref>
在struts.xml文件中,有时候打一个 < 却没有提示,原因是因为没有连接互联网,访问不到"http://struts.apache.org/dtds/struts-2.3.dtd"这个路径 解决方法:1、连接到互联网,工具会自动下载使用2、在MyEclipse中配置一下 配置步骤如下: Window---Preferences--MyEclipse Enterprise …. ---XML-----XML Catalog -- 然后点击Add按钮,添加文件。Location 添加的是struts-2.3.dtd文件的路径,Key Type选择URL,KEY中的内容为http://struts.apache.org/dtds/struts-2.3.dtd,选择OK. 注意:在配置完成之后,struts.xml文件中可能会有一个红叉,按一下回车键,然后在保存一下就可以了
<!--公共的跳转 --><global-results><result name="logins" type="redirectAction"><param name="actionName">login</param><!-- login?code=1001 --><param name="code">1001</param></result></global-results>
文件下载 <action name="download" class="com.peng.action.UserAction" method="download"><result type="stream"> //文件类型<param name="contentType">${fileType}</param> //文件大小<param name="contentLength">${fileLength}</param><param name="contentDisposition">attachment;filename="${fileName}"</param><param name="contentCharSet">UTF-8</param> //指向getInputstream<param name="inputName">inputstream</param></result></action>//actionpublic String download() {return SUCCESS;}public InputStream getInputstream() throws FileNotFoundException {fileName = "zhangqingfeng.doc";File file = new File("E:/Download/",fileName);fileType = map.get(file.getName().substring(file.getName().trim().lastIndexOf(".")));fileLength = file.length();return new FileInputStream(file);}
//文件上传 <action name="upload" class="com.peng.action.UserAction" method="upload"><result type="redirectAction"><param name="actionName">home</param></result></action>//action public String upload() throws Exception{System.out.println("Desc: " + desc);//获取文件名称为临时文件的名称System.out.println("Pic Name: " + pic.getName());System.out.println("Pic length :" + pic.length());//获取文件真正的文件名System.out.println("File Name:" + picFileName);System.out.println("文件类型:" + picContentType);InputStream input = new FileInputStream(pic);OutputStream out = new FileOutputStream(new File("E:/Download/",UUID.randomUUID().toString()+picFileName.substring(picFileName.lastIndexOf("."))));byte[] buffer = new byte[1024]; int len = -1;while ((len=input.read(buffer))!=-1) {out.write(buffer,0,len);}out.flush();out.close();input.close();return SUCCESS;}
转载于:https://www.cnblogs.com/fudapeng/p/3805396.html
Struts2 随笔1相关推荐
- struts2随笔(一)Action、struts.xml、Interceptor细节
Struts2由Struts1和webWork两个经典MVC框架发展起来.与传统的Struts1相比,Struts2允许使用不同的Java对象作为Action.支持更多的视图技术,基于AOP思想的拦截 ...
- struts2.5框架使用通配符指定方法(常见错误)
参考:http://www.cnblogs.com/gsy52300/p/5778754.html 在学习struts框架时经常会使用到通配符调用方法,如下: <package name=&qu ...
- android模拟按键方法,Android随笔之——模拟按键操作的几种方式
前几天转过一篇Android上模拟按键操作.触屏事件的博客,昨天又去找了百度.谷歌了一下,写了一点简单的测试代码,留待不时之需.有需要看之前转载的那篇博客的请看这里→_→转:Android随笔之--使 ...
- java 安卓项目案例_Java - 随笔分类 - android开发实例 - 博客园
随笔分类 - Java 摘要:1.使用标准输入串对象System.inSystem.in.read()一次只读入一个字节数据,而我们通常要取得一个字符串或一组数字,这就很不适合,需要其他方法取得这样的 ...
- struts2 与 sping 整合 控制器中 service注入的问题
以个人见解认为struts1 与spring整合的时候按照习惯,我们会把 action 控制器直接配置到sping中去: eg : 这里以使用元注解方式实现Service注入进行讲解: 控制器关键代码 ...
- Spring整合Struts2
①导入Struts2 jar包 ②在web.xml文件中创建过滤器 <?xml version="1.0" encoding="UTF-8"?> & ...
- Struts2标签库
这是个音乐播放列表 1.queryMusic.jsp <%@ page language="java" import="java.util.*" page ...
- Struts2中Action接收参数
Struts2中Action接收参数的方法主要有以下三种: Struts2中Action接收参数的方法主要有以下三种: 1.使用Action的属性接收参数: a.定义:在Action类中定义属 ...
- struts2笔记01-环境搭建
1.官网下载struts2 struts-2.3.28-all.zip,这个包可谓应有尽有,以后全靠它了! 2.jar包怎么选? (1)struts-2.3.28-all\struts-2 ...
最新文章
- ajax省市联动案例,AJAX案例四:省市联动(示例代码)
- 利用JS面向对象+模块化封装集AJAX请求、基本数据校验、URL参数截取等功能于一身的通用工具模块
- gdb命令中attach使用
- 13--长度最小的子数组
- soapUI中多个TestCase之间传递参数
- 学java需要学c语言吗?
- springMVC浏览器接受json报406错误的解决方法
- Spring boot 与 Spring MVC
- python中正方形内切园_python画出三角形外接圆和内切圆的方法
- 给电脑设置视力保护色
- 电脑x64和x86安装软件的区别讲解分享
- 华为hcie认证工程师设备无故ARP报文丢弃配置
- Flixel横板游戏制作教程(二)— AddingPlayer
- 可缩放矢量图形svg
- Visual C++中的AFX前缀
- 怎么查看笔记本内存条型号_笔记本内存条型号简介以及查看方法【图文教程】...
- 眼球追踪技术给各大科技巨头带来的四大应用前景
- UVALive 4487 - Exclusive-OR -并查集 虚根
- 关于电子科技大学本科生宿舍热水情况调查
- 客户满意度测评模型-「客户满意度指数模型」