Struts2学习之helloworld
2017-05-27 10:36
435 查看
1.基础jar包
下载地址:http://download.csdn.net/detail/m0_37983376/9865635
2.配置web.xml文件,配合StrutsPrepareAndExecuteFilter(必须配置)
3.配置Struts.xml文件,放在src目录下
4.建立一个拦截器实现action接口
5.将项目部署到服务器,并且访问/UserAction
下载地址:http://download.csdn.net/detail/m0_37983376/9865635
2.配置web.xml文件,配合StrutsPrepareAndExecuteFilter(必须配置)
<filter> <filter-name>struts</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
3.配置Struts.xml文件,放在src目录下
<?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> <!-- 按照模块分,必须继承Struts-default,namespace可以看做访问路径,“/”下的action名称 --> <package name="/User" extends="struts-default" namespace="/"> <!-- name访问名 class访问的类路径 method访问方法名,默认execute方法--> <action name="UserAction" class="com.sq.strtus.helloword.UserAction" method="add"> <!-- 上面方法会返回字符串,即name属性值判定 ,默认为success,type值转发的类型(请求转发,重定向)默认请求转发--> <result name="success" type="redirect">/index.jsp</result> </action> </package> </struts>
4.建立一个拦截器实现action接口
package com.sq.strtus.helloword; import com.opensymphony.xwork2.Action; /** *@author sq * */ public class UserAction implements Action { @Override public String execute() throws Exception { System.out.println(11); return Action.SUCCESS; } public String add() throws Exception { System.out.println(11); return Action.SUCCESS; } }
5.将项目部署到服务器,并且访问/UserAction
相关文章推荐
- struts2学习之HelloWorld
- Symbian学习(一)——分析HelloWorldBasic
- Linux设备驱动程序学习(0)-Hello, world!模块
- contiki学习笔记之hello_world
- 张志宇 SERVELET JSP学习讲义-HelloWorldServlet_2
- .Linux设备驱动程序学习(0)——设备驱动介绍& Hello, world!模块 内核参数传递
- wxWidget学习笔记二:Hello World!
- Perl学习日志(1) — Windows下怎么运行Perl程序显示输出"hello,world"语句
- jQuery学习笔记之Helloworld
- Linux设备驱动程序学习(0)-Hello, world!模块
- Linux设备驱动程序学习(0) -设备驱动介绍& Hello, world!模块
- 学习摘录1--Hello, World!
- Linux设备驱动程序学习(0)-Hello, world!模块
- Linux设备驱动程序学习(0)-Hello, world!模块
- Linux设备驱动程序学习(0) -设备驱动介绍& Hello, world!模块
- watir学习之旅(一):从Hello,world开始
- 1.5 Hello, world! 解剖 -JSF实战 -hxzon -jsf学习笔记
- How To Create Struts 2 helloWorld on Eclipse(新建struts2项目)
- 安卓ApiDemos学习 app/Activity/HelloWorld
- Linux设备驱动程序学习(0)-Hello, world!模块