Struts2的简单例子配置第一个struts2例子
2015-02-17 10:09
274 查看
步骤1:
导入struts2相关的jar包,MyEclipse里自带有,比较方便,
步骤2:
创建一个pojo类:
package wei.cheng;
public class LoginAction {
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:
创建一个名为Login.jsp
<form action="Login.action" method="post"><a>
username: <input type="text" name="username"><br>
password:<input type="password" name="password"><br>
<input type="submit" name="submit">
</a></form>
步骤4:
创建一个result.jsp
username:${requestScope.username}<br>
password:${requestScope.password}
以上jsp比较简单,全部直接系统默认的代码都省略了,<html></html>.........
步骤5:
配置一个struts.xml 在src文件夹下,用来映射相关信息。
<?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="default" namespace="/" extends="struts-default">
<action name="Login" class="wei.cheng.LoginAction">
<result name="success">/result.jsp</result>
</action>
</package>
</struts>
步骤6:
在web.xml里加载Struts2.
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<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>
</web-app>
运行jsp显示,完成第一个struts2操作。在Login.jsp输入相关信息,result.jsp
显示信息。
导入struts2相关的jar包,MyEclipse里自带有,比较方便,
步骤2:
创建一个pojo类:
package wei.cheng;
public class LoginAction {
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:
创建一个名为Login.jsp
<form action="Login.action" method="post"><a>
username: <input type="text" name="username"><br>
password:<input type="password" name="password"><br>
<input type="submit" name="submit">
</a></form>
步骤4:
创建一个result.jsp
username:${requestScope.username}<br>
password:${requestScope.password}
以上jsp比较简单,全部直接系统默认的代码都省略了,<html></html>.........
步骤5:
配置一个struts.xml 在src文件夹下,用来映射相关信息。
<?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="default" namespace="/" extends="struts-default">
<action name="Login" class="wei.cheng.LoginAction">
<result name="success">/result.jsp</result>
</action>
</package>
</struts>
步骤6:
在web.xml里加载Struts2.
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<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>
</web-app>
运行jsp显示,完成第一个struts2操作。在Login.jsp输入相关信息,result.jsp
显示信息。
相关文章推荐
- 第一个简单的Struts2的例子
- Struts2的配置和一个简单的例子
- struts2入门-第一个例子==》第一个struts2实例——HelloWorld==》Struts2.0搭建和简单实例==>写一个Steuts2的经典入门案例,做了一个登陆程序作为入门例子
- Struts2入门--第一个简单例子
- Struts2的学习笔记1配置运行环境运行第一个例子Hello word!
- struts2的配置和一个简单的例子
- 配置第一个Struts2的简单登陆程序
- struts2的配置和一个简单的例子
- Struts2基础学习(1)-简单例子与基本配置
- struts2的配置和一个简单的例子
- Java Web : Struts2第一个简单例子 浅解
- nfs 配置的简单例子
- 第一个struts2的例子(转)
- OpenCV1.0与VC60的配置环境与简单例子
- c调用lua 配置简单例子
- struts2 简单配置
- struts2 简单配置
- struts简单例子的分析(含代码注释和配置文件说明)
- Struts2_简单配置
- Struts2的简单例子