第一个 Struts2 程序
来源:互联网 发布:linux ssh ppk 编辑:程序博客网 时间:2024/06/04 23:30
下面主要介绍如何在 myEclipse 下使用 Struts2 搭建一个简单的 hello world 程序
1. Struts2 的环境需求
Servlet API 2.4
JSP API 2.0
Java 5
2. 第一个 struts2 项目的搭建
step1. 首先我们在 myeclipse 下新建一个 web 工程,假设命名为 hellostruts
step2. 鼠标放在项目名称上右键依次选择 MyEclipse –> Project Facets –> Install Apache Struts(2.x) Facet
step3. 这个时候已经配置好 struts2 了,下面我们来看看项目的变化。
(1)项目的 lib-INF 的 lib 目录下多了许多和 struts 相关的 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>*.action</url-pattern> </filter-mapping>
(3) 在 src
目录下多了个 struts.xml
的文件,其初始内容如下:
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"><struts></struts>
step4. 编写第一个 action 类,注意要继承 ActionSupport
这个类,代码如下:
package com.cighao.action;import com.opensymphony.xwork2.ActionSupport;public class HelloStruts extends ActionSupport { @Override public String execute() throws Exception{ //System.out.println("start action"); return "success"; }}
step5. 在 struts.xml
中写入配置信息。代码如下:
<struts> <package name="default" namespace="" extends="struts-default"> <action name="hello" class="com.cighao.action.HelloStruts" > <result name="success">/index.jsp</result> </action> </package></struts>
step6. 添加视图层的内容,我们在 index.jsp 中加入 hello struts2 这段文字。
3. 项目演示
我们部署项目后,在浏览器中输入 localhost:8080/hellostruts/hello.action
就可以看到 index.jsp
中的内容,这里显示的是:
hello struts2
想更多的了解 Struts2 的其他内容可以参见本博客的其他关于 Struts 的文章。
0 0
- 第一个struts2程序
- 第一个struts2程序
- struts2第一个程序
- struts2 第一个程序
- 第一个struts2程序
- Struts2第一个程序
- 第一个struts2程序
- 第一个Struts2程序
- 第一个struts2程序
- 第一个struts2程序
- 第一个 Struts2 程序
- struts2第一个程序
- struts2第一个程序
- 第一个struts2程序
- 第一个Struts2程序
- struts2的第一个程序
- 【Struts2】(1)第一个程序
- Struts2的第一个程序
- 【UML】活动图和状态图
- Android 性能测试实践(一)
- Java高级部分流---换个角度思考流
- 当我们谈论开机的时候我们在谈论什么(三)——段页式存储
- 简单的if ... else ...
- 第一个 Struts2 程序
- opencv读取视频的程序,releae下静态编译,在没有安装opencv的电脑上需要一个解码dll
- C语言运算符的优先级和结合性一览表
- centos6中创建软raid方法
- 关于install vim时出现的问题
- Launching New_configuration has encountered a problem
- 数组引用:C++ 数组做参数 深入分析
- VS2013编写嵌入网页的ATL控件3-网页和控件通信
- 数组竟然是对象