stuts2流程:
3,创建action类,里面包含2中创建javaBean作为属性,然后定义各种处理的方法,方法返回值为String类型
public class StuInfoAction extends ActionSupport{
private Student student;
public String execute(){
System.out.println("+++++++++" + page);
student = new Student();
student.setName("Jack");
student.setId("21100211148");
student.setAge(19);
System.out.println("-----------------execution------");
return SUCCESS;
}
public String delete(){
return "failed";
}
public Student getStudent() {
return student;
}
public void setStudent(Student student) {
this.student = student;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
}
4.首页
<body>
<a href="student/show.action">查看学生信息</a>//点击之后在浏览器中的访问地址为:http://localhost/strutsDemo/student/show.action
<a href="student/delete.action">删除学生信息</a>
</body>
5. web.xml主要用来配置过滤器
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>*.action</url-pattern>
<filter-mapping>
6,配置struts.xml文件:
<package name="/strutsDemo" extends="struts-default" namespace="/student">
<action name="show" class="action类的路径">
<result name="success">jsp显示页</result>
<result name="false">jsp显示页</result>
</action>
<action name="deltet" class="action类的路径" method="delete">
<result name="success">jsp显示页</result>
<result name="false">jsp显示页</result>
</action>
</package>
说明:
1.一个配置文件可以配置多个package,一个package作为一个整个功能模块
访问上面的show.action的时候,根据web.xml中配置的过滤器依次解析访问地址
.name属性对应请求地址中localhost后面的第一级
.extends继承struts-default.xml namespace对应第二级
.action 对应action类中定义的方法
name 对应第三级 class对应action类的路径 method指定要调用action类中的哪个方法
,省略的话默认是调用action类中的execute方法,根据方法的返回值,来决定调用action中的哪一个result指定的显示页面
1,新建lib,导入需要的包
3,创建action类,里面包含2中创建javaBean作为属性,然后定义各种处理的方法,方法返回值为String类型
public class StuInfoAction extends ActionSupport{
private Student student;
public String execute(){
System.out.println("+++++++++" + page);
student = new Student();
student.setName("Jack");
student.setId("21100211148");
student.setAge(19);
System.out.println("-----------------execution------");
return SUCCESS;
}
public String delete(){
return "failed";
}
public Student getStudent() {
return student;
}
public void setStudent(Student student) {
this.student = student;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
}
4.首页
<body>
<a href="student/show.action">查看学生信息</a>//点击之后在浏览器中的访问地址为:http://localhost/strutsDemo/student/show.action
<a href="student/delete.action">删除学生信息</a>
</body>
5. web.xml主要用来配置过滤器
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>*.action</url-pattern>
<filter-mapping>
6,配置struts.xml文件:
<package name="/strutsDemo" extends="struts-default" namespace="/student">
<action name="show" class="action类的路径">
<result name="success">jsp显示页</result>
<result name="false">jsp显示页</result>
</action>
<action name="deltet" class="action类的路径" method="delete">
<result name="success">jsp显示页</result>
<result name="false">jsp显示页</result>
</action>
</package>
说明:
1.一个配置文件可以配置多个package,一个package作为一个整个功能模块
访问上面的show.action的时候,根据web.xml中配置的过滤器依次解析访问地址
.name属性对应请求地址中localhost后面的第一级
.extends继承struts-default.xml namespace对应第二级
.action 对应action类中定义的方法
name 对应第三级 class对应action类的路径 method指定要调用action类中的哪个方法
,省略的话默认是调用action类中的execute方法,根据方法的返回值,来决定调用action中的哪一个result指定的显示页面