struts 第一个小示例(登录)
1 加入struts2 需要的包
附件中
2 修改web.xml 增加
<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 做一个jsp的页面内容,如下(主体部分)
<body>
<form name="loginForm" action="<%=request.getContextPath()%>/login//userLogin" method="post">
<input type="text" name="user.userName" /><br/>
<input type="submit" name="submit" value="确定"/>
</form>
</body>
4 com.lxb.domain包中增加一个类
package com.lxb.domain;
public class User {
private String userName;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
5 com.lxb.action 中的UserLoginAction.java
package com.lxb.action;
import com.lxb.domain.User;
public class UserLoginAction {
private User user;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String execute()
{
return "success";
}
}
6 测试,可以跳转了,记的做个userInfo.jsp。