strtus2搭建步骤:
1.拷贝所需jar到WEB工程目录下的lib
2.配置WEB.xml文件,配置过滤器Filter
<filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
3.编写login.jsp:
<form action="login.action" method="post"> <h1>用户登录</h1> 账号:<input type="text" name="userName"/><br/> 密码:<input type="password" name="passWord"><br/> <input type="submit" value="登录"/> </form>
4.创建LoginAction类继承ActionSupport类,重写execute()
package com.liu.web.action; import com.opensymphony.xwork2.ActionSupport; /** * 用户登录的action * @author Administrator * */ public class LoginAction extends ActionSupport{ private String userName; private String passWord; @Override public String execute() throws Exception { System.out.println("账号:"+userName); System.out.println("密码:"+passWord); return "success"; } 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; } }
5.拷贝struts.xml配置文件到src目录下:
<constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default"> <action name="login" class="com.liu.web.action.LoginAction"> <result name="success">/success.jsp</result> </action> </package>
本文出自 “老牛Java” 博客,请务必保留此出处http://liuyj.blog.51cto.com/2340749/1715860
原文地址:http://liuyj.blog.51cto.com/2340749/1715860