页面无法显示数据,确认已经进入action方法,JSONObject.fromObject(map);这句代码无法执行未出现错误
struts.xml配置<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEstrutsPUBLIC"-//ApacheSoftwa...
struts.xml配置
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="json" namespace="/" extends="json-default">
<action name="auAction" class="auAction">
<result name="cg">index.jsp</result>
<result type="json">
<param name="root">result</param>
</result>
</action>
</package>
</struts>
jsp页面
<div class="items" id="ss">
</div>
action中的方法
//查询
public String selAll() throws Exception{
//调用查询全部的方法
int curPage=1;
int pageSize=9;
if(request.getParameter("page")!=null){
curPage=Integer.parseInt(request.getParameter("page"));
}
if(request.getParameter("rows")!=null){
pageSize=Integer.parseInt(request.getParameter("rows"));
}
//得到商品总条数
int total=auBiz.getTotal(" from Auction");
List<Auction>list=auBiz.selAll(curPage, pageSize, " from Auction");
//response.setContentType("appliction/json;charset=utf-8");
Map map=new HashMap();
map.put("total", total);
map.put("rows",list);
result = JSONObject.fromObject(map);
return SUCCESS;
}
js代码
$(function(){
$("#tt").datagrid({
url:'auAction!selAll',
columns:[[
{field:'auctionname',title:'名称',width:80,align:'right'},
{field:'auctiondesc',title:'描述',width:120,resizable:false},
{field:'auctionstarttime',title:'开始时间',width:80,align:'right',sortable:true},
{field:'auctionendtime',title:'结束时间',width:80,align:'right',sortable:true},
{field:'auctionstartprice',title:'起拍价',width:80,align:'right',sortable:true}
]],
pagination:true,
pageList:[10,20,2,5]
})
}) 展开
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="json" namespace="/" extends="json-default">
<action name="auAction" class="auAction">
<result name="cg">index.jsp</result>
<result type="json">
<param name="root">result</param>
</result>
</action>
</package>
</struts>
jsp页面
<div class="items" id="ss">
</div>
action中的方法
//查询
public String selAll() throws Exception{
//调用查询全部的方法
int curPage=1;
int pageSize=9;
if(request.getParameter("page")!=null){
curPage=Integer.parseInt(request.getParameter("page"));
}
if(request.getParameter("rows")!=null){
pageSize=Integer.parseInt(request.getParameter("rows"));
}
//得到商品总条数
int total=auBiz.getTotal(" from Auction");
List<Auction>list=auBiz.selAll(curPage, pageSize, " from Auction");
//response.setContentType("appliction/json;charset=utf-8");
Map map=new HashMap();
map.put("total", total);
map.put("rows",list);
result = JSONObject.fromObject(map);
return SUCCESS;
}
js代码
$(function(){
$("#tt").datagrid({
url:'auAction!selAll',
columns:[[
{field:'auctionname',title:'名称',width:80,align:'right'},
{field:'auctiondesc',title:'描述',width:120,resizable:false},
{field:'auctionstarttime',title:'开始时间',width:80,align:'right',sortable:true},
{field:'auctionendtime',title:'结束时间',width:80,align:'right',sortable:true},
{field:'auctionstartprice',title:'起拍价',width:80,align:'right',sortable:true}
]],
pagination:true,
pageList:[10,20,2,5]
})
}) 展开
展开全部
你既然用异步表格了那这个地方就应该用void
public void selAll() throws Exception{
把这个方法加到页面,然后掉一下
String json= JsonUtils.toJSONString(你的json对象);
//把你的json对象转成字符串需要去网上找下工具类
this.doAjaxObjectWrite(json, MimeUtil.JSON);
后面需要把json信息输出到流里面
/**
* Ajax请求时向页面写入数据
*
* @author LCC
* @param 输出内容
* ,mime类型,mime字符集,页面字符集
* @param ajax
* string,mime type,mime character encoding,character encoding
* @throws IOException
*/
public void doAjaxObjectWrite(String ajaxStr, String mime, String mimeCE, String ce) {
if (ajaxStr != null && ajaxStr.length() > 0) {
mime = mime == null ? MimeUtil.DEFAULT : mime;
mimeCE = mimeCE == null ? MimeUtil.DEFAULT_MIME_CE : mimeCE;
ce = ce == null ? MimeUtil.DEFAULT_CHARACTER_ENCODING : ce;
String ct = mime + ";charset=" + mimeCE;
response.setContentType(ct);
response.setHeader("Cache-Control", "no-cache");
response.setCharacterEncoding(ce);
try {
response.getWriter().write(ajaxStr);
response.getWriter().flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询