struts2基础
来源:互联网 发布:新浪微博个性域名删除 编辑:程序博客网 时间:2024/05/21 08:04
很快,又开始了新的学期的学习。这几个月,我们的老师讲主要教授我们ssh技术,以便我们以后的开发使用。
老师首先介绍了Struts2技术一些相关信息:
Struts2是在WebWork2基础发展而来的。和Struts1一样,Struts2也属于MVC的web框架。不过有一点大家需要注意的是:Struts2和Struts1有很大区别,实现机制完全不一样。Stru2ts2开始支持基于Annotation的配置。
接下来就是让我门动手去搭建Struts2的环境,一般步骤就是如下几步:
1.找到开发Struts应用需要使用到的JAR文件,因为只是开发初期,用到的不是很多,只用了如下的几个jar包:
2.编写Struts2的配置文件( 在这里就以一个简单的例子来示例一下配置文件的编写):
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="zdosft" namespace="/test"extends="struts-default"> <action name="helloworld"class="cn.itcast.action.HelloWorldAction" method="execute"> <result name="success">/WEB-INF/page/hello.jsp</result> </action> </package> </struts>
3.在web.xml中加入Struts2 MVC框架启动配置:
简单搭建好Struts2的环境之后,老师就带着我们开始了第一个Struts2的应用,也就是由一个Action类主控制的struts程序:
Action类:
package action;import java.io.UnsupportedEncodingException;public class HelloAction {private String message;public String getMessage() {return message;}public void setMessage(String message) {this.message = message;}// 所有的方法必须返回值Stringpublic String execute() {this.message = new String("第一个");return "success";}}
struts2配置:
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd"><struts><package name="hello" namespace="/hello" extends="struts-default"> <action name="test" class="action.HelloAction" method="execute"> <result name="success"> URL </result> </action></package></struts>
我们只需要在浏览器地址栏输入“http://localhost:8080/struts_hello/hello/test”,看效果。
0 0
- struts2基础
- Struts2基础
- struts2基础
- struts2基础
- Struts2 基础
- struts2基础
- struts2基础
- Struts2基础
- Struts2基础
- Struts2基础
- struts2--基础
- Struts2基础
- struts2基础
- Struts2基础
- Struts2基础
- Struts2基础
- Struts2 基础
- Struts2基础
- LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- 算法时间复杂度-线性阶
- 《C++ Primer第五版》读书笔记(10)-DYNAMIC MEMORY
- SpringMVC源码剖析(四)- DispatcherServlet请求转发的
- C++中BOOL和bool的区别
- struts2基础
- CentOS linux的目录结构
- 估计概率构造短语翻译表
- 安装lnmp nginx php mysql环境 -magento
- 算法时间复杂度-对数阶
- HDU4501:小明系列故事——买年货(三重背包)
- virtualbox下安装redhat 6.5(附镜像下载)
- 详细解析ESP寄存器与EBP寄存器
- 输入n个数和输出调整后的n个数