struts2配置struts.xml
程序员文章站
2022-07-12 16:13:48
...
1. struts2配置struts.xml
1) pageckage配置 name 包名 extends 继承 namespace 包命名空间 abstract 抽象包 2) action配置 nameaction 名 class 处理类 method 方法 新建项目HeadFirstStruts2Chap02_03
ForeStudent.java package com.andrew.action; import com.opensymphony.xwork2.ActionSupport; public class ForeStudent extends ActionSupport { @Override public String execute() throws Exception { System.out.println("执行了ForeStudent Action的默认方法"); return SUCCESS; } } struts.xml <package name="foreground" namespace="/fore" extends="struts-default"> <action name="studentList" class="com.andrew.action.ForeStudent"> <result name="success">${pageContext.request.contextPath}/success.jsp</result> </action> </package> success.jsp Ok! http://localhost:8080/HeadFirstStruts2Chap02_03/fore/studentList Ok!
BackStudent.java package com.andrew.action; import com.opensymphony.xwork2.ActionSupport; public class BackStudent extends ActionSupport { @Override public String execute() throws Exception { System.out.println("执行了BackStudent Action的默认方法"); return SUCCESS; } public String show() throws Exception{ System.out.println("执行了 BackStudent show方法"); return SUCCESS; } } struts.xml <package name="background" namespace="/back" extends="struts-default"> <action name="studentList" class="com.andrew.action.BackStudent" method="show"> <result name="success">${pageContext.request.contextPath}/success.jsp</result> </action> </package> success.jsp Ok! http://localhost:8080/HeadFirstStruts2Chap02_03/back/studentList 执行了 BackStudent show方法
下一篇: struts2处理传入多个值