struts2学习
来源:互联网 发布:深圳缇嘉服饰淘宝店铺 编辑:程序博客网 时间:2024/05/20 04:31
1、struts2中所需的jar包必须统一,否则在加载过程中会出现错误。
2、关键的五个jar包
2、关键的五个jar包
3、用户登陆为例来实习struts2
A、创建web 项目 test
B、将五个jar包拷贝到lib下
C、写业务逻辑类
com.icss.LoginService
public class LoginService{
public boolean login(String username,String password){
if("lydia".equals(username.trim())&&"aa".equals(password)){
return true;
}else{
return false;
}
}
}
D、写Action类
com.icss.LoginAction
public class LoginAction{
private String username;
private String password;
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
//该方法将被自动调用,实现控制逻辑,Action必须有的方法
public String execute(){
LoginService loginS=new LoginService();
boolean flag=loginS.login(username, password);
if(flag){
return "success";
}else{
return "fail";
}
}
public String execute(){
LoginService loginS=new LoginService();
boolean flag=loginS.login(username, password);
if(flag){
return "success";
}else{
return "fail";
}
}
}
E、配置文件
web.xml
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping></web-app>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping></web-app>
在src创建 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>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="loginTest" extends="struts-default"> 红字可以为任意名称
<action name="login" class="com.icss.etc.action.LoginAction">
<result name="success">/login.jsp</result>
<result name="fail">/index.jsp</result>
</action>
</package>
</struts>
<action name="login" class="com.icss.etc.action.LoginAction">
<result name="success">/login.jsp</result>
<result name="fail">/index.jsp</result>
</action>
</package>
</struts>
F、页面
login.jsp
<body>
<form action="login.action" method="post">
<center>
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="username"/></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="password"/></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" value="登陆"/></td>
</tr>
</table>
</center>
</form>
</body>
<form action="login.action" method="post">
<center>
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="username"/></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="password"/></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" value="登陆"/></td>
</tr>
</table>
</center>
</form>
</body>
0 0
- [Struts2]Struts2学习总结
- Struts2 学习
- Struts2学习
- 学习struts2
- 学习struts2
- 学习struts2
- 学习Struts2
- Struts2学习
- struts2学习
- 学习struts2
- struts2学习
- struts2学习
- struts2学习
- struts2学习
- struts2学习
- Struts2学习
- struts2学习
- struts2学习
- ubuntu10.10下安装jdk7
- 论windows装gensim的艰辛历程
- java+city-picker自定义省市区选择
- 2016 年最受欢迎的编程语言是什么?
- centos7下使用yum安装mysql
- struts2学习
- Java Native Interface
- Android应用市场发布
- 排序
- missing required architecture i386 in file错误解决
- oralce基础--转载
- Centos7开启端口
- 如何解压.gz的压缩文件
- const