好久没有用框架了,学的东西不用就会忘掉,今天开始重学三大框架
struts2介绍我就不多说了,想必你们应该比我还熟悉,现在我就讲下配置之类的问题
1.新建web项目
2.首先你要导入相关的包;因为新浪的bug问题我就发不了,你们也可以右击项目文件 点击myeclipse-Add Struts Capabilities选择Struts2.1
3.你的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>
4.新建一个reg.jsp页面写一个form表单提交 请求到action
<form action="user" method="post">
姓名:<input type="text" name="name"/><br>
密码:<input type="password" name="password"/>
<input type="submit" value="提交"/>
</form>
5.新建一个UserAction类继承ActionSupport实现execute方法
@Override
public String execute() throws Exception {
return SUCCESS;
}
6.新建一个struts.xml文件,里面这么写
<?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="user" extends="struts-default">
<action name="user" class="com.qm.UserAction">
<result name="index">/index.jsp</result>
</action>
</package>
</struts>
这里的action就是你reg.jsp页面提交到的Action class为处理的类
result为返回到哪!现在是返回到index.jsp页面
7.修改UserAction类
String name;
String password;
@Override
public String execute() throws Exception {
//System.out.println("测试成功");
System.out.println("用户名:"+name);
System.out.println("密码:"+password);
//index是struts.xml返回的名字
return "index";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
struts2介绍我就不多说了,想必你们应该比我还熟悉,现在我就讲下配置之类的问题
1.新建web项目
2.首先你要导入相关的包;因为新浪的bug问题我就发不了,你们也可以右击项目文件 点击myeclipse-Add Struts Capabilities选择Struts2.1
3.你的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>
4.新建一个reg.jsp页面写一个form表单提交 请求到action
<form action="user" method="post">
姓名:<input type="text" name="name"/><br>
密码:<input type="password" name="password"/>
<input type="submit" value="提交"/>
</form>
5.新建一个UserAction类继承ActionSupport实现execute方法
@Override
public String execute() throws Exception {
return SUCCESS;
}
6.新建一个struts.xml文件,里面这么写
<?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="user" extends="struts-default">
<action name="user" class="com.qm.UserAction">
<result name="index">/index.jsp</result>
</action>
</package>
</struts>
这里的action就是你reg.jsp页面提交到的Action class为处理的类
result为返回到哪!现在是返回到index.jsp页面
7.修改UserAction类
String name;
String password;
@Override
public String execute() throws Exception {
//System.out.println("测试成功");
System.out.println("用户名:"+name);
System.out.println("密码:"+password);
//index是struts.xml返回的名字
return "index";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
现在工作就完成了。打开浏览器输入地址访问!
我的新浪博客和csdn一起发的!这是我的博客文章地址:http://blog.sina.com.cn/s/blog_b34a581f0102w16n.html!大神们请轻虐