分类目录归档:Struts

Struts2 jQuery ajax 示例

映射文件
struts.xml




    
    
    
    
    
    
    
        
        
            
            
		
	

核心路由文件
web.xml



    Struts Blank
    
        
        struts2
        
        org.apache.struts2.dispatcher.FilterDispatcher
    

    
    
        struts2
        /*
    

UserAction.java

package com.stamhe;

import java.io.UnsupportedEncodingException;
import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport{
    private static final long serialVersionUID = 1L;
    private String dateJSON;
    private String name;
    private String Sex;

    public String execute() throws UnsupportedEncodingException{
        this.name = java.net.URLDecoder.decode(name, "UTF-8");
        System.out.println("从客户端接受到的数据: " + name);
        dateJSON="[{name: 'stamhe', age: 30}, {name: 'hestam', age: 32}]";
        return SUCCESS;
    }

    public String getDateJSON(){
        return dateJSON;
    }

    public void setDateJSON(String dateJSON){
        this.dateJSON = dateJSON;
    }

    public String getName(){
        return name;
    }

    public void setName(String name){
        this.name = name;
    }

    public String getSex(){
        return Sex;
    }

    public void setSex(String Sex){
        this.Sex = Sex;
    }
}

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>


    
        
        ajax
        
        

    
    
        
        
要显示数据的区域