1.struts2 初识

struts2 简单登陆

将表单输入登陆信息显示在第二个页面

1.copy struts2 jar包
commons-logging-1.0.4.jar
freemarker-2.3.8.jar
struts2-core-2.0.11.jar
xwork-2.0.4.jar
ognl-2.6.11.jar

2.修改Tomcat server.xml
<Context path="/struts2" docBase="E:\MyEclipse\struts2\WebRoot" reloadable="true" />


3.修改项目 部署配置文件web.xml
<filter>
    
<filter-name>struts</filter-name>
    
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>

<filter-mapping>
    
<filter-name>struts</filter-name>
    
<url-pattern>/*</url-pattern>
</filter-mapping>


3.新建class处理action
package org.test.struts.action;

public class ActionLogin {
    
private String username;
    
private String password;
    
public String getUsername() {
        
return username;
    }

    
public void setUsername(String username) {
        
this.username = username;
    }

    
public String getPassword() {
        
return password;
    }

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

    
public String execute() throws Exception{
        
return "success";
    }

}



3.新建struts.xml
在WebRoot/WEB-INF/classes文件夹下
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd"
>
<struts>
    
<package name="struts" extends="struts-default">
        
<action name="login" class="org.test.struts.action.ActionLogin" >
            
<result name="success" >/result.jsp</result>
        
</action>
    
</package>
</struts>


4.建立login.jsp
    <form action="login.action" method="post">
        username:
<input type="text" name="username" /><br>
        password:
<input type="password" name="password" /><br>
        
<input type="submit" value="submit" />
    
</form>



5.建立result.jsp
    username:${request.username }
    password:${request.password }


posted @ 2008-02-21 00:03  Xsi64  阅读(127)  评论(0编辑  收藏  举报