怎样通过extjs从一个jsp页面读取一个json字符串的内容?
我想用EXTJS实现把从一个JSP页面上的json字符串,在EXT的页面上显示,为什么总是得不到JSP页面上的内容。在JSP页面上这样写的:jsonText.jsp<%@...
我想用EXTJS实现把从一个JSP页面上的json字符串,在EXT的页面上显示,为什么总是得不到JSP页面上的内容。在JSP页面上这样写的:jsonText.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN"
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%out.print("[{name:'aaa',age:28,sex:'女'},{name:'bbb',age:28,sex:'男子'},{name:'ccc',age:30,sex:'女'}]");%>
</body>
</html>
EXT页面代码:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link type="text/css" rel="stylesheet" href="../../extjs/resources/css/ext-all.css">
<script type="text/javascript" src="../../extjs/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../../extjs/ext-all.js"></script>
<script type="text/javascript">
Ext.onReady(function(){
var _store=new Ext.data.JsonStore({
proxy:new Ext.data.HttpProxy({
url:"localhost:8080/dag/jsonTest.jsp"
}),
fields:["name","age","sex"]
});
_store.on("load",function(_store){
alert("hi");
alert(_store.getCount());
alert(Ext.util.JSON.encode(_store.getAt(0).data));
});
_store.load();
});
</script>
</head>
<body>
</body>
</html>
文件路径是对的,直接通过服务器能看到内容,但是通过EXT就是读不到任何内容,为什么在EXT页面上总是加载不到JSP页面的内容?请大家帮帮忙,给看一下是哪的问题?一定给加分。 展开
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN"
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%out.print("[{name:'aaa',age:28,sex:'女'},{name:'bbb',age:28,sex:'男子'},{name:'ccc',age:30,sex:'女'}]");%>
</body>
</html>
EXT页面代码:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link type="text/css" rel="stylesheet" href="../../extjs/resources/css/ext-all.css">
<script type="text/javascript" src="../../extjs/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../../extjs/ext-all.js"></script>
<script type="text/javascript">
Ext.onReady(function(){
var _store=new Ext.data.JsonStore({
proxy:new Ext.data.HttpProxy({
url:"localhost:8080/dag/jsonTest.jsp"
}),
fields:["name","age","sex"]
});
_store.on("load",function(_store){
alert("hi");
alert(_store.getCount());
alert(Ext.util.JSON.encode(_store.getAt(0).data));
});
_store.load();
});
</script>
</head>
<body>
</body>
</html>
文件路径是对的,直接通过服务器能看到内容,但是通过EXT就是读不到任何内容,为什么在EXT页面上总是加载不到JSP页面的内容?请大家帮帮忙,给看一下是哪的问题?一定给加分。 展开
2个回答
展开全部
我记得我曾经也遇到过,好像是这样解决的,把jsp中除了<%%>以外的内容都删掉。
对于你这个 jsonText.jsp 而言
最后就留下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%out.print("[{name:'aaa',age:28,sex:'女'},{name:'bbb',age:28,sex:'男子'},{name:'ccc',age:30,sex:'女'}]");%>
如果不行的话,你改成
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-store"); //HTTP1.1
response.setHeader("Pragma", "no-cache"); //HTTP1.0
response.setDateHeader("Expires", 0); //prevents catching at proxy server
response.getWriter().write("[{name:'aaa',age:28,sex:'女'},{name:'bbb',age:28,sex:'男子'},{name:'ccc',age:30,sex:'女'}]");
%>
你试试
对于你这个 jsonText.jsp 而言
最后就留下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%out.print("[{name:'aaa',age:28,sex:'女'},{name:'bbb',age:28,sex:'男子'},{name:'ccc',age:30,sex:'女'}]");%>
如果不行的话,你改成
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-store"); //HTTP1.1
response.setHeader("Pragma", "no-cache"); //HTTP1.0
response.setDateHeader("Expires", 0); //prevents catching at proxy server
response.getWriter().write("[{name:'aaa',age:28,sex:'女'},{name:'bbb',age:28,sex:'男子'},{name:'ccc',age:30,sex:'女'}]");
%>
你试试
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询