博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[原创]java WEB学习笔记54:Struts2学习之路--- 编写Struts2 的第一个程序,HelloWord,简述 package ,action,result...
阅读量:4453 次
发布时间:2019-06-07

本文共 3958 字,大约阅读时间需要 13 分钟。

本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用

内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系。

本人互联网技术爱好者,互联网技术发烧友

微博:伊直都在0221

QQ:951226918

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

 

1.详细介绍原理

  1)关于Struts.xml

1 
2 5 6
7
16
17 18
25
28
34
/struts2/input.jsp
35
36 37 38
39
/struts2/details.jsp
40 41
42 43
44 45

 

 

   

  ① package

 

  

 

② action

 

 

③ result

 

 

 

 

2.代码

代码结构

 

index.jsp

1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2     pageEncoding="UTF-8"%> 3  4  5  6 
7 Insert title here 8 9 10 11 12 Product Input13 14

 

 

 

input.jsp

1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2     pageEncoding="UTF-8"%> 3  4  5  6 
7 input page 8 9 10 11
12 ProductName:
13
14 15 ProductDesc:
16
17 18 ProductPrice:
19
20 21
22
23 24

 

detail.jsp

 

1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2     pageEncoding="UTF-8"%> 3  4  5  6 
7 detail page 8 9 10 11 ProductId:${productId }12
13 ProductName:${productName }14
15 ProductDesc:${productDesc }16
17 ProductPrice:${productPrice }18
19 20 21 22

 

 

Product.java

1 package com.jason.struts.helloword; 2  3 public class Product { 4      5     private Integer productId; 6     private String productName; 7     private String productDesc; 8       9     private double productPrice;10     11     12     13     public String save(){14         15         System.out.println(this);16         return "details";17     }18     @Override19     public String toString() {20         return "Product [productId=" + productId + ", productName="21                 + productName + ", productDesc=" + productDesc22                 + ", productPrice=" + productPrice + "]";23     }24 25     public Integer getProductId() {26         return productId;27     }28 29     public void setProductId(Integer productId) {30         this.productId = productId;31     }32 33     public String getProductName() {34         return productName;35     }36 37     public void setProductName(String productName) {38         this.productName = productName;39     }40 41     public String getProductDesc() {42         return productDesc;43     }44 45     public void setProductDesc(String productDesc) {46         this.productDesc = productDesc;47     }48 49     public double getProductPrice() {50         return productPrice;51     }52 53     public void setProductPrice(double productPrice) {54         this.productPrice = productPrice;55     }56     57 58 59 }

 

 

struts.xml

1 
2 5 6
7
13
14 15
20
21
/struts2/input.jsp
22
23 24 25
26
/struts2/details.jsp
27 28
29 30 31 32
33 34 35 36

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  1.由 product-input.action 转到/struts2/input.jsp, 在struts.xml 中配置一个acton

  

1         
6
7
/struts2/input.jsp
8
9

 

 

2.由input.jsp 页面的action: product-save.action 到 /struts2/details.jsp 页面。在Product 中定义一个save方法,且返回值为 details 

1 
2
/struts2/details.jsp
3 4

 

转载于:https://www.cnblogs.com/jasonHome/p/5729665.html

你可能感兴趣的文章
Zookeeper全解析——Paxos作为灵魂
查看>>
集合-强大的集合工具类:java.util.Collections中未包含的集合工具
查看>>
CSS清除浮动
查看>>
数据库基础-数据库常用命令总结
查看>>
java8 按对象属性值排序
查看>>
[转帖]nvidia nvlink互联与nvswitch介绍
查看>>
[cnblog新闻]历史性时刻:云硬件支出首次高于传统硬件
查看>>
[转帖]Oracle dba_objects和all_objects 最大的区别
查看>>
【转帖】国产x86处理器KX-6000发布
查看>>
RSA算法及其在iOS中的使用
查看>>
04-js的运算符
查看>>
第三天 while循环 及其用法
查看>>
Delphi 10 seattle 去掉自带的代码连接线
查看>>
构建高并发高可用的电商平台架构实践(转)
查看>>
Geometry Imager Viewport Filter
查看>>
Guava API学习之Optional 判断对象是否为null
查看>>
九度oj 题目1025:最大报销额
查看>>
数字及字符串
查看>>
【转载】OmniGraffle (二)基础绘图和模具
查看>>
一些提高开发效率的 Category
查看>>