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;
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
<?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-INF\hy.jsp</result> <result name="two">/WEB-INF\dl.jsp</result> </action> </package> </struts>