---
title: "struts2步骤"
author: "wuai"
date: "2015-07-19T18:51:33Z"
tags: ["Struts"]
categories: ["企业架构"]
slug: "struts2"
draft: false
lastmod: "2015-07-19T18:51:33Z"
id: 2228553
url: "https://wuai.iteye.com/blog/2228553"
---

1、添加jar包 2、在web.xml中配置过滤器 struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter struts2 /* 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"); =&gt; 3、//第三种传值方式,通过servlet的api传值 ServletActionContext.getRequest().setAttribute("ccc", "hello"); =&gt; 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)、页面

title:

(2)、Action中获取 private File\[] photo; private String\[] photoFileName; private String\[] photoContentType; .. set/get方法 .. public String fileUpload(){ for(int i=0;i 4.在struts.xml中的action引用： /WEB-INF/message/fileUpload.jsp /WEB-INF/message/{1}.jsp