<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="t" uri="/WEB-INF/templet.tld" %>
<%@ taglib prefix="app" uri="/WEB-INF/app.tld" %>
<%@ page import="com.ps.user.*" %>
<app:jsphelper type="js" src="js/reference.js" />
<app:jsphelper type="js" src="js/json/json.js" />
<%-- 页面信息 --%>
<table align="center" valign="top" width="98%" border="0">
<tr><td>
<t:querypanel templet="STUSER_TEACHER_QUERY" vo="queryVo" col="2"/>
</td></tr>
<tr><td align="center">
<app:link οnclick="javascript:onAction('QUERY')" img="images/button/search_red.gif" swapimg="images/button/search_blue.gif" width="84" height="21" border="0" enter="true"/>
<app:link οnclick="javascript:onAction('RESET')" img="images/button/reset_red.gif" swapimg="images/button/reset_blue.gif" width="84" height="21" border="0"/>
<app:link οnclick="javascript:right()" img="images/button/reset_red.gif" swapimg="images/button/reset_blue.gif" width="84" height="21" border="0"/>
</td></tr>
</table>
<div id="dd" style="display: none;">
</div>
<%
IUser user = (IUser)session.getAttribute("user");
%>
<%String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()+ ""
+ request.getContextPath() + "/"; %>
<input type="hidden" id="user_id" value="<%=user.getUserId() %>" />
<input type="hidden" id=basePath value="<%=basePath %>" />
<input type="hidden" id=vv value="<%=request.getAttribute("vv") %>" />
<!-- http://localhost:8080/ygw-stub/-->
<script type="text/javascript">
<!--
setRefInfo("POPCOURSE","queryVo","选择课程");
//-->
</script>
<script type="text/javascript">
function kk(){
var userid=document.getElementById("user_id").value;
var basePath=document.getElementById("basePath").value;
var urlpath=basePath+"ajaxtext/jj.do?userid="+userid;
alert("ssssssss---"+urlpath);
$.ajax({
url: urlpath,
type: 'POST',
dataType: 'json',
success: function(res){
alert("success");
alert(res);
},
complete:function(res){
alert("success222");
alert(res.length);
///json字符串转化成json对象方法:
var myJSONObject2 = eval('(' + res + ')');
var myJSONObject3=res.parseJSON();
var myJSONObject4=JSON.parse(res);
alert(myJSONObject2);
alert(myJSONObject3);
alert(myJSONObject4);
}
});
}
/
var xmlHttp;
function ca() {
var userid=document.getElementById("user_id").value;
var basePath=document.getElementById("basePath").value;
var urlpath=basePath+"ajaxtext/jj.do?userid="+userid+"&sql=ssssqqqllll";
alert(urlpath);
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlHttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch (e) {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
}
xmlHttp.open("GET", urlpath, true);
xmlHttp.onreadystatechange = updatePage;
xmlHttp.send();
}
function updatePage() {
if (xmlHttp.readyState==4 && xmlHttp.status==200){
alert("haha");
var response = xmlHttp.responseText;
alert("*******"+response);
var vvv="[{'kk':'mm'}]";
var myJSONObject22 = eval('(' + vvv + ')');
//var myJSONObject55=vvv.parseJSON();
alert(myJSONObject22[0].kk);
}
}
function right(){
var userid=document.getElementById("user_id").value;
var basePath=document.getElementById("basePath").value;
var urlpath=basePath+"ajaxtext/jj.do?userid="+userid+"&sql2=ssssqqqllll";
jQuery.ajax( {
url:urlpath,
type:'post',
async:false,
data:'sql='+'hkhkhhhkhk',
success:function(res){
if(""!=res){
alert(res);
}
}
});
}
</script>
package com.ygw.stu.stuser.teacher;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.*;
import net.sf.json.JSONArray;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.ps.base.CommonError;
import com.ps.pub.DataManager;
import com.ps.pub.ValueObject;
import com.ygw.stu.base.BaseAction;
/**
* @author:
* @version:
* @Create Time:2011-12-01 19:17:35
* @Description: 业务处理Action
*/
public class AjaxTextAction extends ActionSupport {
private String res;
public String getRes() {
return res;
}
public void setRes(String res) {
this.res = res;
}
public String execute(){
this.res="[{'hh':'hhaa'}]";
PrintWriter out;
try {
String sql=ServletActionContext.getRequest().getParameter("sql");
System.out.println("sql-----"+sql);
String sql2=ServletActionContext.getRequest().getParameter("sql2");
System.out.println("sql2-----"+sql2);
out = ServletActionContext.getResponse().getWriter();
//out.println(res);
this.res="[{'jj':'jjaa'}]";
//out.write(res);
} catch (IOException e) {
e.printStackTrace();
}
// return "res";
return this.SUCCESS;
}
public static void main(String[] ff){
AjaxTextAction aa=new AjaxTextAction();
aa.getJsonArray();
}
/**
* 得到数的json数据实例
*/
public void getJsonArray(){
List list = new ArrayList();
AjaxJsonTreeBean jb1 = new AjaxJsonTreeBean();
jb1.setId("id1");
jb1.setpId("-1");
jb1.setEname("dian1");
jb1.setClick("ff('jjj')");
AjaxJsonTreeBean jb2 = new AjaxJsonTreeBean("id2","id1","dian12","ff('ff')");
list.add(jb1);
list.add(jb2);
JSONArray ja = JSONArray.fromObject(list);
System.out.println( ja.toString() );
// [{"click":"ff('jjj')","ename":"dian1","id":"id1","pId":"-1"},
// {"click":"ff('ff')","ename":"dian12","id":"id2","pId":"id1"}]
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" namespace="/ajaxtext" extends="json-default">
<!-- ajax start /jsp/stu/stuser/teacher/search.jsp teacher.list json-default-->
<action name="jj" class="com.ygw.stu.stuser.teacher.AjaxTextAction">
<result name="success" type="json">
<param name="root">res</param>
</result>
</action>
<!-- ajax end -->
</package>
</struts>