<package name="default" namespace="/" extends="struts-default"> <action name="example" class="com.example.struts.action.expAction"> </package>
<package name="default" namespace="/" extends="struts-default"> <action name="example" class="com.example.struts.action.expAction"> <result name = "success">/success.jsp</result> <result name = "error">/error</result> </package>
(ActionName)!(methodName).action
//访问product中的edit()方法 product!edit.action
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品列表</title>
</head>
<body>
<table border="1">
<tr>
<th>商品ID</th>
<th>商品名称</th>
<th>数量</th>
<th colspan="2">操作</th>
</tr>
<tr>
<td>1001</td>
<td>小米手机</td>
<td>128</td>
<td><a href="product!edit.action?productId=1001" rel="external nofollow" >编辑</a></td>
<td><a href="product!del.action?productId=1001" rel="external nofollow" >删除</a></td>
</tr>
<tr>
<td>1002</td>
<td>佳能相机</td>
<td>100</td>
<td><a href="product!edit.action?productId=1002" rel="external nofollow" >编辑</a></td>
<td><a href="product!del.action?productId=1002" rel="external nofollow" >删除</a></td>
</tr>
</table>
</body>
</html>```
package com.qst.chapter03.action;
import com.opensymphony.xwork2.ActionSupport;
public class ProductAction extends ActionSupport {
private int productId;
public int getProductId() {
return productId;
}
public void setProductId(int productId) {
this.productId = productId;
}
// 编辑商品
public String edit() {
System.out.println("编辑商品" + productId);
// ...省略一些编辑商品的业务
return "edit";
}
// 删除商品
public String del() {
System.out.println("删除商品" + productId);
// ...省略一些删除商品的业务
return "del";
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>编辑商品</title>
</head>
<body>
${param.productId}商品编辑
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>删除商品</title>
</head>
<body>
${param.productId}商品删除成功!
</body>
</html>
<?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>
<!-- 指定Struts2处于开发阶段,可以进行调试 -->
<constant name="struts.devMode" value="true" />
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<!-- Struts2的Action都必须配置在package里,此处使用默认package -->
<package name="default" namespace="/" extends="struts-default">
<!-- 定义一个名为user的Action,实现类为com.qst.chapter03.action.LoginAction -->
<action name="product" class="com.qst.chapter03.action.ProductAction">
<result name="edit">/edit.jsp</result>
<result name="del">/del.jsp</result>
</action>
</package>
</struts>
<action name="editproduct" class="com.qst.chapter03.action.ProductAction" method = "edit"> <result name="edit">/edit.jsp</result> </action> <action name="delproduct" class="com.qst.chapter03.action.ProductAction" method = "del"> <result name="del">/del.jsp</result> </action>
<struts>
<!-- 演示通配符的使用方法 -->
<package name="product" extends="struts-default">
<action name=" * product" class="com.qst.chapter03.action.ProductAction" method = "{1}">
<result name="edit">/edit.jsp</result>
<result name="del">/del.jsp</result>
</action>
</package>
</struts>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有