这个是文件的一命名 主看Student开头的
============================首先看首页就是接按钮==================================
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<!-- 以下是使用通配符来配置 -->
<!--
详细说明一下这一段的含义,用Student_add这一段细节一下:
Student_add 中这个字段对应的其实是struts.xml中action name="*_*"
第一个*好匹配了Student 第二个*好匹配了add 待会在配置文件进一步说明
-->
<input type="button" value="添加学生" onclick="return window.location='Student_add'"/>
<input type="button" value="删除学生" onclick="return window.location='Student_delete'"/>
</body>
</html>
===========================然后是Action==========================
package org.demo.struts;
import com.opensymphony.xwork2.ActionSupport;
public class StudentAction extends ActionSupport {
public String add() {
return "add_success";
}
public String delete() {
return "delete_success";
}
}
===================然后是怎么在sturt.xml中使用通用配置符配置=========================
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.devMode" value="true"/>
<!--以下是用通配符来配置文件 -->
<!--
详细说明一下 用Student_add来说明一下
name="*_*"匹配所有这样的形式
在class中{1}达标了name="*_*"中的第一个*也就是(Student)结果是StudentAction这个类
method="{2}"中的{2}代表了name="*_*"中的第二个信号 也就是add 也就说明了这个action调用add这个方法
result name=""中的值也就是一样 它是execute返回的执行结果 是要跳转的页面
-->
<package name="studentAction" namespace="/" extends="struts-default">
<action name="*_*" class="org.demo.struts.{1}Action" method="{2}">
<result name="{2}_success">{1}_{2}_success.jsp</result>
</action>
</package>
</struts>
==============自总总结:
一个好的项目,一个好的项目经理,必须对每个约束进行约束,好的约束优化了好的配置,
在这里我们可以看到一个通用配置符,只要做好了好的约束,配置文件中就只需要一个配置就搞定
大大简介了配置文件,所以作为一个项目经理必须对开发中的约束做好最好的约束 比如:项目的名称,方法的名称如何定义,这些都是在开发中一定要
约定好的