39Struts

39Struts_第1张图片

搭建struts框架

1.导包
2.书写Action类


package com.cj.a_hello;

public class HelloAction {
    
    public String hello(){
        System.out.println("hello world");
        return "success";
    }

}

3.书写src/struts.xml


 
    

    
        
            /hello.jsp
        
    

4.将struts2核心过滤器配置到web.xml


  
    struts
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
  
这个类可以用shift+control+t查找  

  
    struts
    /*
  
  

访问http://localhost:8080/WEB39-strusts01/hello/HelloAction
访问流程

39Struts_第2张图片

struts架构


39Struts_第3张图片
39Struts_第4张图片

struts.xml配置





    
    
        
        
            /hello.jsp
        
    

struts常量配置

1. struts默认常量配置位置

39Struts_第5张图片

2.修改struts2常量配置(方式先后也是加载顺序)

1)方式1: 在src下创建struts.properties

39Struts_第6张图片
struts.i18n.encoding=UTF8

2)方式2:src/struts.xml (重点)


3)方式3:在项目的web.xml中


  
    struts.i18n.encoding
    UTF-8
  

常用的常量配置


    
    
访问的后缀为action或者没有后缀
    
    
    

struts2配置的进阶

action类

package com.cj.b_dynamic;

//动态方法调用
public class Demo1Action {
    public String add(){
        System.out.println("添加用户!");
    return "success";
    }
    public String delete(){
        System.out.println("删除用户!");
    return "success";
}
    public String update(){
        System.out.println("修改用户!");
    return "success";
}
    public String find(){
        System.out.println("查找用户!");
    return "success";
}
    
    
}
39Struts_第7张图片

    

动态方法调用

第一种


    
    
        
            
            
                /hello.jsp
            
        

访问
http://192.168.0.88:8080/WEB39-strusts01/dynamic/Demo1Action!add

第二种(重点)参数占位符


            
            
                /hello.jsp
            
        

访问
http://192.168.0.88:8080/WEB39-strusts01/dynamic/Demo1Action_delete

struts2中的默认配置


            
            
            
            
            
            
            
                /hello.jsp
            
        

action类的详解

1.POJO普通Java类,不需要继承,不需要实现
2.实现Action接口
3.继承ActionSupport

你可能感兴趣的:(39Struts)