第一个分派struts2实例

dl页面;

  

<h1>用户登录</h1>
  <hr>

  <form action="<%=path %>/yz!login.action" method="post">

   用户名<input type="text" name="name">
    密码<input type="password" name="password"> 
    <input type="submit" value="登录">
  </form>


hy页面;

 <a href="<%=path %>/yz!reglster.action">退出</a>

 
View Code

Action ;

package com.st.action;

import com.opensymphony.xwork2.ActionSupport;

public class YzAction extends ActionSupport {

 public String login() throws Exception {
  System.out.println("login");
  return "loginok";

 }
 public String reglster() throws Exception {
  System.out.println("reglster");
  return "reglsterok";

 }


}
View Code

struts.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>

 <package name="denlu" namespace="/" extends="struts-default">
  <action name="yz" class="com.st.action.YzAction">
   <result name="loginok">/WEB-INFhy.jsp</result>
   <result name="reglsterok">/WEB-INFdl.jsp</result>
  </action>
 
 </package> 
 
</struts>    
View Code
原文地址:https://www.cnblogs.com/laohan110/p/3524978.html