配置步骤:

1.在你的strut2目录下找到例子项目,把它的 lib 下的jar拷贝到你的项目。例如我的:struts-2.3.24\apps\struts2-blank

2.struts-2.3.24\apps\struts2-blank\WEB-INF\src\ ( 例子项目的WEB-INF\src )下的 struts.xml 文件拷到你的项目src下,并且删除里面的内容,只留下根标签

  <strut> </strut>

3.在你的项目的web.xml下配置struts,看看例子项目的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>

4.helloworld演示:

先准备3个页面一个类:

1)index.jsp

 <body>
<br>
<a href="product-input.action">Input</a>
</body>

2) input.jsp

<body>

        <br>
<form action="product-save.action">
<table>
<tr>
<td>ProductId</td>
<td><input type="text" name="productId"></td>
</tr>
<tr>
<td>ProductName</td>
<td><input type="text" name="productName"></td>
</tr>
<tr>
<td>ProductDesc</td>
<td><input type="text" name="productDesc"></td>
</tr>
<tr>
<td>ProductPrice</td>
<td><input type="text" name="productPrice"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="提交" /></td>
</tr>
</table>
</form> </body>

3) details.jsp

<body>

            <br><br>
<table>
<tr>
<td>ProductId</td>
<td>${productId }</td>
</tr>
<tr>
<td>ProductName</td>
<td>${productName }</td>
</tr>
<tr>
<td>ProductDesc</td>
<td>${productDesc }</td>
</tr>
<tr>
<td>ProductPrice</td>
<td>${productPrice }</td>
</tr>
</table> </body>

4) 准备一个类

package com.gy.helloworld;

public class Product {

    private Integer productId;
private String productName;
private String productDesc;
private Double productPrice; public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getProductDesc() {
return productDesc;
}
public void setProductDesc(String productDesc) {
this.productDesc = productDesc;
}
public Double getProductPrice() {
return productPrice;
}
public void setProductPrice(Double productPrice) {
this.productPrice = productPrice;
}
@Override
public String toString() {
return "Product [productId=" + productId + ", productName="
+ productName + ", productDesc=" + productDesc
+ ", productPrice=" + productPrice + "]";
} }

5)以上目录结构为:

6) 配置struts.xml

<struts>
<package name="Struts2-1" extends="struts-default">
<action name="product-input">
<result>/WEB-INF/pages/input.jsp</result>
</action> <action name="product-save" class="com.gy.helloworld.Product" method="save">
<result name="details">/WEB-INF/pages/details.jsp</result>
</action>
</package>
</struts>

7)注意:

a: extends="struts-default" 为继承struts默认拦截器配置

b:在第二个action里面 class="com.gy.helloworld.Product" method="save" 刚才我们的Product 类没有save()方法,一定要加上,且返回值为

<result name="details">/WEB-INF/pages/details.jsp</result>标签里面的name属性值:
public String save() {
System.out.println("product save ..");
return "details"; }

c:注意jsp各标签name属性和Product类的字段的对应。

Struts2 的 helloworld的更多相关文章

  1. 使用maven+eclipse搭建最简单的struts2的helloworld

    使用maven+eclipse搭建最简单的struts2的helloworld 一.web分层结构简介 1.web[细]粒度分层结构: 按细粒度分层可以分为以下6种: 1).表现层:html/css/ ...

  2. Struts2之HelloWorld

    首先既然是开发Struts程序的话,那么自然需要用到Struts2开发包,Struts2是apache旗下的开源框架,所有的开发包和源代码都可以在Apache官网下载. 那么,就来开始编写第一个Str ...

  3. 创建一个struts2的HelloWorld

    1.下载struts2的jar包 http://struts.apache.org/download.cgi#struts255 下载一个稳定版本Struts 2.3.31 里面提供了maven ja ...

  4. 使用MyEclipse 9.0 创建 struts2 的HelloWorld 工程

    作为眼高手低的典范,必须痛改前非,好好动手多做开发! 本文是struts2的入门指导,权当笔记! 在MyEclipse中,配置Apache tomcat 7.x 服务器 创建新的Web project ...

  5. 2.第一个Struts2程序-HelloWorld程序

    1.新建Web Project项目:Study_Struts2 2.新建HelloWordAction.java类 3.复制struts.xml文件到src目录下,配置struts.xml文件内容如下 ...

  6. struts2的HelloWorld的基本过程

    login.jsp中 <form action="Login"... 该页面提交后, web.xml中设置的过滤器会起作用     <filter>        ...

  7. Struts2学习笔记 - HelloWorld总结

    相信网上已经有很多关于struts2的HelloWorld可参考,我这里就不重复了,没个学struts2的人都会做过很多个HelloWorld,而我这里就总结一下一个简单的HelloWorld 我在一 ...

  8. 菜鸟学Struts2——Struts工作原理

    在完成Struts2的HelloWorld后,对Struts2的工作原理进行学习.Struts2框架可以按照模块来划分为Servlet Filters,Struts核心模块,拦截器和用户实现部分,其中 ...

  9. 2. Struts2 基础

    1. Struts2简介 Struts2是一个WEB端MVC框架.作为比较早的MVC 框架之一,Struts2在使用中还是比较多的.虽然个人感受没有SpringMVC还那么的好用 Struts2 官网 ...

随机推荐

  1. ExtJs之Ext.core.DomHelper.append

    <!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...

  2. kafka配置

    官网:http://kafka.apache.org/ 主要有3种安装方式: 1. 单机单broker 2. 单机多broker 3. 多机多broker 1. wget http://mirror. ...

  3. 算法导论:Trie字典树

    1. 概述 Trie树,又称字典树,单词查找树或者前缀树,是一种用于快速检索的多叉树结构,如英文字母的字典树是一个26叉树,数字的字典树是一个10叉树. Trie一词来自retrieve,发音为/tr ...

  4. 欧拉工程第52题:Permuted multiples

    题目链接 题目: 125874和它的二倍,251748, 包含着同样的数字,只是顺序不同. 找出最小的正整数x,使得 2x, 3x, 4x, 5x, 和6x都包含同样的数字. 这个题目相对比较简单 暴 ...

  5. linux下ping加时间戳实时输出到文件 放后台运行

    放后台运行命令:setsid 实时输出命令:unbuffer 加时间戳:awk '{ print $0"\t" strftime("%D_%H:%M:%S",s ...

  6. Hadoop基础教程之高级编程

    从前面的学习中,我们了解到了MapReduce整个过程需要经过以下几个步骤: 1.输入(input):将输入数据分成一个个split,并将split进一步拆成<key, value>. 2 ...

  7. TestDirector创建域或工程

    一.打开TestDirector 1.打开TestDirector,进入如下页面 点击左上角"Site Administrator"进入 2.在输入框里输入正确的Site Admi ...

  8. [iOS]ARC和MRC下混编

    1.在MRC工程中使用ARC的文件(例如AFNetworking,SDWebImage,MJRefresh等)在Build Phases里找到对应.m 在后面添加-fobjc-arc(代表这个文件使用 ...

  9. CentOS查看系统信息命令和方法

    收集整理的一些linux查看系统信息的命令和方法: 一.linux查看服务器系统信息的方法: 1.查看主机名/内核版本/CPU构架: # uname -n -r -p -o localhost.loc ...

  10. SSIS ->> Control Flow And Data Flow

    In the Control Flow, the task is the smallest unit of work, and a task requires completion (success, ...