Struts2通配符问题

来源:互联网 发布:加工中心编程格式 编辑:程序博客网 时间:2024/06/10 22:38
struts.xml中的配置
  <action name="*_*" class="com.tg.struts2.action.{1}Action" method="{2}">            <result >{1}_{2}_success.jsp</result>        </action>

{1}代表

 name="*_*"
第一个*的值 {2}代表第2个*


使用通配符要约定好Action类名方法名,JSP文件名,url地址(约定优于配置)

示例 Class

package com.tg.struts2.action;import com.opensymphony.xwork2.ActionSupport;public class TeacherAction extends ActionSupport {public String add(){return SUCCESS;}public String delete(){return SUCCESS;}public String update(){return SUCCESS;}}


示例URL

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%><%String path = request.getContextPath()+"/";//String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>  <base href="<%=path %>">       <title>首页</title>    </head>    <body>  <a href="User_add">添加用户</a>   <a href="User_delete">删除用户</a>   <a href="User_update">更新用户</a><br>  <a href="Teacher_add">添加老师</a>   <a href="Teacher_delete">删除老师</a>   <a href="Teacher_update">更新老师</a><br>  </body></html>

示例jsp文件


最后注意一点如果一个Action传递过来能同时匹配多个Action配置 优先精确级别的,含*的,无论数量为同级别,按配置先后匹配。

0 0