jquery load()方法在struts2中的使用。(注意不适用struts1.x)

 jquery load()方法在struts2中的使用。(注意不适用struts1.x)

load()方法的局部加载

 

 主页面edit.jsp

<%@ page language="java" pageEncoding="utf-8" contentType="text/html; charset=utf-8"%>
<%@ taglib uri="/struts-tags"   prefix="s"%>
<html>
	<head>
		<title>jquery load()方法在struts2中的使用</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-store">
		<META HTTP-EQUIV="Expires" CONTENT="0">
	<script type="text/javascript" src="../script/jquery-1.7.min.js"></script>
	
	</head>
	<body>
  <h1>load</h1>
  
  <input type="text"  name="aa"><br/>
  <input type="text"  name="bb"><br/>
  
  <input type="button"  value="aaa"  onclick="uuuuuuuuuuuu('a')" >
  <input type="button"  value="bbb"  onclick="uuuuuuuuuuuu('b')" >
  <input type="button"  value="ccc"  onclick="uuuuuuuuuuuu('c')" ><br/>
  -------------aaaaaaaaaaaaaaa<br/>
  
  <div id="div_1" >

  </div>
  --------bbbbbbbbbbbbb
  <script type="text/javascript">
  function uuuuuuuuuuuu(a){
  	 $("#div_1").html("");
	  $("#div_1").load("load/loadAction_load.action?name="+a);
  }
  //gettttLoad("b");
  </script>
    
  </body>
</html>


 

局部加载页面list.jsp

<%@ page language="java" pageEncoding="utf-8" contentType="text/html; charset=utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<html>
	<head>
		<title>My JSP 'index.jsp' starting page</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-store">
		<META HTTP-EQUIV="Expires" CONTENT="-1">
		<script type="text/javascript" src="../script/jquery-1.7.min.js"></script>
		<script type="text/javascript">
	$.ajaxSetup({
		cache : false
	//关闭AJAX相应的缓存
	});
</script>
	</head>
	<body>
		<s:iterator id="data" value="studentList" var="data">
			<s:property value="name" />
			<br />
		</s:iterator>
	</body>
</html>


Action.java

package cn.itcast.load;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

public class LoadAction extends ActionSupport {

	String name;

	public List<Student> studentList = new ArrayList<Student>();

	public String init() {
		System.out.println(name);
	
		return "success";
	}
	public String load() {
		System.out.println(name);
		
		if ("a".equals(name)) {
			studentList.add(new Student("3", "a", 5));
		} else if ("b".equals(name)) {
			studentList.add(new Student("2", "aa", 4));
			studentList.add(new Student("3", "bbbb", 5));
		} else if ("c".equals(name)) {
			studentList.add(new Student("1", "aa", 3));
			studentList.add(new Student("2", "bb", 4));
			studentList.add(new Student("3", "cccc", 5));
		}
                  //跳到部局页面
		return "list";
	}

	public String getName() {
		return name;
	}

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

}


 

struts.xm

<struts>
    <package name="load" namespace="/load" extends="struts-default">      
     
      <action name="loadAction_*" class="cn.itcast.load.LoadAction" method="{1}">
         <result name="success">/load/edit.jsp</result>
         <result name="list">/load/list.jsp</result>
       </action>
    </package>
</struts>


 

你可能感兴趣的:(jquery,struts,String,iterator,input,button)