struts2配置struts.xml

阅读更多
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


      
          ${pageContext.request.contextPath}/success.jsp
      


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


    
        ${pageContext.request.contextPath}/success.jsp
    


success.jsp

Ok!

http://localhost:8080/HeadFirstStruts2Chap02_03/back/studentList
执行了 BackStudent show方法

你可能感兴趣的:(Java,struts2)