struts征程:1.初识struts2
来源:互联网 发布:js 正整数正则表达式 编辑:程序博客网 时间:2024/05/21 17:38
1.struts2在开发中所必须用到的jar包导入到项目的lib目录下
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>
当然,大家应该知道struts2的核心技术是基于拦截器实现的
3.写一个简单的Action
CustomerAction.java
package com.sdu.crm.action;import org.directwebremoting.util.SystemOutLoggingOutput;import com.opensymphony.xwork2.Action;import com.opensymphony.xwork2.ActionSupport;import com.opensymphony.xwork2.ModelDriven;import com.sdu.crm.dao.impl.CustomerDaoImpl;import com.sdu.crm.pojo.Customer;import com.sun.net.httpserver.Authenticator.Success;public class CustomerAction extends ActionSupport {private static final long serialVersionUID = 1L;private Customer customer;public Customer getCustomer() {return customer;}public void setCustomer(Customer customer) {this.customer = customer;}/** * * @author fighter24h * 自定义的action方法 * 其形式同execute方法 * 返回String,抛出Exception * 方法名字对应struts配置文件中的method属性 */public String addCustomerInfo() throws Exception {return "addCustomerInfoOk";}}
4.配置acton对应的strtus的xml文件
示例:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts><!-- package name:用来实现继承的 namespace:用来解决重名的,访问的时候充当路径--><package name="action-customer-lzm" extends="struts-default"namespace="/customer"><!--name:action的名字,访问的使用需要用到 class:具体的action是哪个类,写全路径method:我们自己定义的方法,而不是执行execute方法--><action name="addCustomerInfo" class="com.sdu.crm.action.CustomerAction"method="addCustomerInfo"><!--name:来自method的返回值,可以自定义! --><result name="addCustomerInfoOk">/index.jsp</result></action></package></struts>
- struts征程:1.初识struts2
- struts 2学习进阶 初识struts2(一)
- 《深入浅出struts2》--第二章,初识struts
- J2EE Struts2 学习笔记001 ---- 初识struts 2
- Struts2初识(1)-struts实现简单登录
- struts2-1.struts初感
- 初识struts
- 初识struts
- 初识struts
- struts初识
- 初识Struts
- 初识struts
- struts2 初识
- 初识Struts2
- 初识struts2
- 初识struts2
- 初识Struts2
- Struts2初识
- WPF之Binding基础十一 MultiBinding多路绑定
- Oracle数据库默认使用的是乐观锁还是悲观锁?
- WinForm程序--常用方法
- Android屏幕背光调整机制
- Hadoop安全云盘开发(第4篇)
- struts征程:1.初识struts2
- C++ 预处理器 标志粘贴
- Android 检测网络是不是打开
- InterruptedException的解读
- C#解决MDI窗体闪屏的方法 --(arvin推荐)
- 由一个园友因为上传漏洞导致网站被攻破而得到的教训
- Android GridView 一行显示数据(包括图片和文本),解决的办法是计算数据占该行的宽度是多少
- 关于Android LCD和键盘背光亮度 .
- ActivityGroup + GridView + ViewFlipper 实现选项卡