struts2入门案例

dl.jsp;

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

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

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

action; 

 private String name;
 private String password;
 private String tip;
 public String getTip() {
  return tip;
 }

 public void setTip(String tip) {
  this.tip = tip;
 }

 public String getName() {
  return name;
 }

 public void setName(String name) {
  this.name = name;
 }

 public String getPassword() {
  return password;
 }

 public void setPassword(String password) {
  this.password = password;
 }

 public String execute() throws Exception {
  // TODO Auto-generated method stub
  System.out.println(name+"/"+password);
  if (name != null && "ab".equals(password)) {
   return "ok";
  }
  this.setTip("密码错误");
  return "no";

 }

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="denglu" namespace="/" extends="struts-default">
  <action name="yz" class="com.st.action.YzAction">
   <result name="one">/WEB-INFhy.jsp</result>
   <result name="two">/WEB-INFdl.jsp</result>
  </action>
 
 </package> 
 
</struts>    
View Code
原文地址:https://www.cnblogs.com/laohan110/p/3524980.html