`

struts2步骤

阅读更多
1、添加jar包
2、在web.xml中配置过滤器
<filter>
       <filter-name>struts2</filter-name>
       <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
3、编写struts.xml文件
4、编写action
普通模式,在action中直接指定method=""
基于请求参数
http://localhost:8080/struts2/user!add
http://localhost:8080/struts2/user?method:add
基于通配符
5、action向jsp传值
1、   私有属性和其对应的set/get方法
在跳转的页面通过 ${私有属性} EL表达式获取
2、//第二种,通过ActionContext.getContext()方法
ActionContext.getContext().put("abc", "123"); => <s:property value="#abc" />
3、//第三种传值方式,通过servlet的api传值
ServletActionContext.getRequest().setAttribute("ccc", "hello"); =>
<s:property value="#request.ccc" />
6、jsp向action中传值
1、私有属性 和其对应的set/get方法
http://localhost:8080/struts2/user_addInput?username=abc&password=123
private String username;
private String password;
set/get方法
System.out.println(username+"="+password);
7、OGNL表达式:

8、ValueStack:
件图片
9、ModelDriven:

10、struts2的文件上传: (用到了common-fileupload、common-io 包)
(1)、页面
<form action="msg_fileUpload" method="post" enctype="multipart/form-data">
title:<input name="title" type="text"/><br>
<input type="file" name="photo" /> <br>
<input type="file" name="photo" /> <br>
<input type="file" name="photo" /> <br>
<input type="file" name="photo" /> <br>
<input type="submit" value="提交" >
   </form>
(2)、Action中获取
private File[] photo;
private String[] photoFileName;
private String[] photoContentType;
..
set/get方法
..

public String fileUpload(){
for(int i=0;i<photo.length;i++){
File p = photo[i];
String name = photoFileName[i];
String type = photoContentType[i];
System.out.println(name+"\"+type);
FileUitls.copyFile(p,new File("d:/ttest/"+name));
}
}
11、拦截器:
1.写一个类,实现abstractintercptor抽象类
2.在intercept 写业务
3.在struts.xml中配置intercptor:
<interceptors>
<interceptor name="helloInterceptor" class="cn.xxx.struts2.interceptor.HelloInterceptor"></interceptor>
<interceptor-stack name="myStack">
<interceptor-ref name="defaultStack" />
<interceptor-ref name="helloInterceptor" />
</interceptor-stack>
</interceptors>
<!--
<default-interceptor-ref name="myStack" ></default-interceptor-ref>
-->
4.在struts.xml中的action引用:
<action name="msg_*" class="cn.xxx.struts2.action.MessageAction" method="{1}">
<interceptor-ref name="myStack" />
<result name="success" >/WEB-INF/message/fileUpload.jsp</result>
<result name="{1}" >/WEB-INF/message/{1}.jsp</result>
</action>

分享到:
评论

相关推荐

    Struts2 code jar+实现struts2步骤文档

    Struts2 code jar+实现struts2步骤文档

    Struts2项目开发流程简明实例

    功能: ...  否则页面跳转到login.jsp页面等待...2. 项目添加Struts2类包支持 3. 设置核心控制器(配置web.xml) 4. 创建业务逻辑控制器(Action) 5. 创建视图页面 6. 创建struts.xml配置Action 7. 部署和运行struts2项目

    整合struts2和spring源代码(可以直接在tomcat中运行)

    可以直接运行,并对整合spring和struts2步骤及需要注意的事项进行类总结 整合spring和struts2总结 1.将struts2和spring中的库文件复制到项目下(可以查看WEB-INF\lib目录下的文件) 注意:struts2-spring-...

    配置struts2的步骤

    自己总结的struts2的配置步骤!让我们菜鸟们起步

    Struts2 创建简单步骤

    Struts2 创建简单步骤 使用

    Struts2快速学习步骤

     struts2 的概念和作用  struts2 的HelloWorld  简单分析struts2 的运行流程  struts2 配置文件加载  struts.xml 配置文件详解  struts2 常量文件修改  Action 动作类的三种写法  Action 动作类的三...

    Struts2漏洞2.0.xx升级为Struts-2.5.12步骤

    本人测试通过。Struts2漏洞2.0.xx升级为Struts-2.5.12步骤。压缩包包含升级步骤,及struts2.5.12所需要的libs.

    SSM(Spring+Struts2+Mybatis)整合步骤

    SSM(Spring+Struts2+Mybatis)整合步骤 纯手写

    Struts2全解Struts2全解

    Struts2 软件下载 Struts2 比较重要的类 操作步骤及框架配置 struts运行机制 2、简单的struts2程序 3、struts2配置文件 4、cion主要内容 Namespace、自定义Action、路径问题、通配符、包含模块配置文件、默认...

    struts2项目部署

    struts2项目部署 适合小白 ,内含jar包 具体步骤请参考http://blog.csdn.net/hsun924/article/details/16847177

    Velocity语法以及整合struts2总结

    文档详细描述了Velocity整合struts2步骤,以及velocity的语法规范

    Struts2教程

    Struts2 Struts2 Struts2 教程 1 1 1 :第一个 Struts2 Struts2 Struts2 程序 在本系列教程中我们将学习到 Struts2 的各种技术。在本教程中使用的工具和程序库的版本 如下: 开发工具: MyEclipse6 Web 服务器: ...

    struts2分页代码的示例

    下面是我用Struts2做的一个分页显示实例,基本的思路是:把数据库表中的每一行数据封装成一个对象,用一个返回类型为List的方法返回这些对象,接着在Struts2的action里面定义一个List属性,用这个List来接收从数据库...

    struts2文件上传源码和步骤

    struts2+myeclipse实现文件上传,源码和实现步骤,详细过程!很适合初学者阅读!

    创建一个简单的struts2的步骤

    教你轻松创建一个简单的struts2的步骤

    spring-mybatis-struts2-master ——demo

    spring mybatis struts2的一个框架整合,列出主要代码

    用Struts2新建一个应用的方法步骤

    用Struts2新建一个应用的方法步骤用Struts2新建一个应用的方法步骤: 1.首先新建一个Web Project。File——new——Web Project,在Project Name中输入一个合法的名字。例如:struts2 2. 单击采单Window——...

    spring整合struts2详细步骤

    spring-struts2整合详细步骤。适合初学者参考。内容详尽。

    Struts2的开发步骤

    Struts2的开发步骤和特性,要求和注意事项,部署运行,

    struts2流程与流程图

    一个请求在Struts 2框架中的处理大概分为以下几个步骤。  客户端提交一个(HttpServletRequest)请求,如上文在浏览器中输入 http://localhost: 8080/bookcode/ch2/Reg.action就是提交一个(HttpServletRequest)...

Global site tag (gtag.js) - Google Analytics