第一个分派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-INF\hy.jsp</result>
   <result name="reglsterok">/WEB-INF\dl.jsp</result>
  </action>
 
 </package> 
 
</struts>    
View Code

 

posted @ 2014-01-18 12:35  老汉!  阅读(154)  评论(0编辑  收藏  举报