本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用
内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系。
本人互联网技术爱好者,互联网技术发烧友
微博:伊直都在0221
QQ:951226918
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1.详细介绍原理
1)关于Struts.xml
1 2 5 67 16 17 18 25 44 4528 34 36 37 38/struts2/input.jsp 3539 42 43/struts2/details.jsp 40 41
① package
② action
③ result
2.代码
代码结构
index.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 4 5 6 7Insert 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 723 24input page 8 9 10 11
detail.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 4 5 6 7detail 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 67 13 14 15 20 33 34 35 3621 23 24 25/struts2/input.jsp 2226 29 30 31 32/struts2/details.jsp 27 28
1.由 product-input.action 转到/struts2/input.jsp, 在struts.xml 中配置一个acton
1 67 9/struts2/input.jsp 8
2.由input.jsp 页面的action: product-save.action 到 /struts2/details.jsp 页面。在Product 中定义一个save方法,且返回值为 details
12 /struts2/details.jsp 3 4