Action 代码
//查询出页面所需数据
public String findAll(){
//此处需要servlet的打印流和相应对象
HttpServletResponse response = ServletActionContext.getResponse();
//设置相应对象
response.setContentType("text/html");
//设置编码
response.setCharacterEncoding("UTF-8");
if(pr!=null){
try {
String pname = new String(pr.getPname().getBytes("ISO-8859-1"),"UTF-8");
String manufact=new String(pr.getManufact().getBytes("ISO-8859-1"),"UTF-8");
String price = new String(pr.getPrice().getBytes("ISO-8859-1"),"UTF-8");
String model=new String(pr.getModal().getBytes("ISO-8859-1"),"UTF-8");
System.out.println(pname+":"+manufact+":"+price+":"+model);
pr.setManufact(manufact);
pr.setModal(model);
pr.setPname(pname);
pr.setPrice(price);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//执行dao方法获取数据
List<Product> li = new ProductDao().findAll(page,pr);
System.out.println(li.toString());
//new 出一个json对象
JSONObject j = new JSONObject();
for(int i=0;i<li.size();i++){
JSONObject jn = new JSONObject();
//添加json格式
jn.put("id", li.get(i).getId());
jn.put("pname", li.get(i).getPname());
jn.put("modal", li.get(i).getModal());
jn.put("price", li.get(i).getPrice());
jn.put("manufact", li.get(i).getManufact());
jn.put("stockNum", li.get(i).getStockNum());
jn.put("inDate",String.valueOf(li.get(i).getInDate()));
j.put(i, jn);
}
response.setCharacterEncoding("UTF-8");
try {
PrintWriter out = response.getWriter();
out.print(j);
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("0000000000000000000000000");
return null;
}
JSP
<table id="selectable1">
<tr class="ui-widget-content">
<th>序号</th>
<th>商品名</th>
<th>型号</th>
<th>价格</th>
<th>生产厂家</th>
<th>库存数量</th>
<th>入库时间</th>
</tr>
</table>
<table id="selectable">
<s:iterator value="#li" var="it">
<tr><td><s:property value="#it.id"/></td><td><s:property value="#it.pname"/></td><td><s:property value="#it.modal"/></td><td><s:property value="#it.price"/></td><td><s:property value="#it.manufact"/></td><td><s:property value="#it.stockNum"/></td><td><s:property value="#it.inDate"/></td></tr>
</s:iterator>
</table>
</div>JSP 不知道怎么弄了。。急!!
//查询出页面所需数据
public String findAll(){
//此处需要servlet的打印流和相应对象
HttpServletResponse response = ServletActionContext.getResponse();
//设置相应对象
response.setContentType("text/html");
//设置编码
response.setCharacterEncoding("UTF-8");
if(pr!=null){
try {
String pname = new String(pr.getPname().getBytes("ISO-8859-1"),"UTF-8");
String manufact=new String(pr.getManufact().getBytes("ISO-8859-1"),"UTF-8");
String price = new String(pr.getPrice().getBytes("ISO-8859-1"),"UTF-8");
String model=new String(pr.getModal().getBytes("ISO-8859-1"),"UTF-8");
System.out.println(pname+":"+manufact+":"+price+":"+model);
pr.setManufact(manufact);
pr.setModal(model);
pr.setPname(pname);
pr.setPrice(price);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//执行dao方法获取数据
List<Product> li = new ProductDao().findAll(page,pr);
System.out.println(li.toString());
//new 出一个json对象
JSONObject j = new JSONObject();
for(int i=0;i<li.size();i++){
JSONObject jn = new JSONObject();
//添加json格式
jn.put("id", li.get(i).getId());
jn.put("pname", li.get(i).getPname());
jn.put("modal", li.get(i).getModal());
jn.put("price", li.get(i).getPrice());
jn.put("manufact", li.get(i).getManufact());
jn.put("stockNum", li.get(i).getStockNum());
jn.put("inDate",String.valueOf(li.get(i).getInDate()));
j.put(i, jn);
}
response.setCharacterEncoding("UTF-8");
try {
PrintWriter out = response.getWriter();
out.print(j);
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("0000000000000000000000000");
return null;
}
JSP
<table id="selectable1">
<tr class="ui-widget-content">
<th>序号</th>
<th>商品名</th>
<th>型号</th>
<th>价格</th>
<th>生产厂家</th>
<th>库存数量</th>
<th>入库时间</th>
</tr>
</table>
<table id="selectable">
<s:iterator value="#li" var="it">
<tr><td><s:property value="#it.id"/></td><td><s:property value="#it.pname"/></td><td><s:property value="#it.modal"/></td><td><s:property value="#it.price"/></td><td><s:property value="#it.manufact"/></td><td><s:property value="#it.stockNum"/></td><td><s:property value="#it.inDate"/></td></tr>
</s:iterator>
</table>
</div>JSP 不知道怎么弄了。。急!!
解决方案 »
- gt-grid列表默认全选中
- 写个程序可以加载任意,一种加载数据库文件
- java如何操作连接数据库,和操作web中的表格
- 谁有eWebEditor在线编辑器,带后台的JSP版?
- 老鸟帮下忙,在Debian上做jsp,开发环境选Eclipse,要安装哪些东西?
- java.sql.SQLException: No operations allowed after connection closed.
- 寻求高级JAVA程序员合作开发网站
- 用response类的方法JSP怎么打开新窗口呀?
- 关于初始化参数的问题
- 怎么在Tag中得到当前的会话???
- 【JS】如何直接自定义设置打印预览的显示比率
- Android 客户端的那些事儿 !!!
function testxJsonAjax()
{
var url ="<%=urlroot%>/criterion.do?method=josns&bmid="+document.getElementById('bmid').value;
new Ajax.Request(url,{onComplete:showResponsesx});
}
function showResponsesx(xmlHttp)
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
var result = xmlHttp.responseText;
var str = eval("("+result+")");
while(document.all.bzid.options.length>0)
{
document.all.bzid.options.remove(0);
}
var objSelect = document.getElementById('bzid');
var objOption = new Option();
for(var i=0;i<str.users.length;i++)
{
var objSelect = document.getElementById('bzid');
var objOption = new Option();
objOption.text= str.users[i].name;
objOption.value= str.users[i].id;
objSelect.options.add(objOption);
}
}
}
} public void josns(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){
response.setContentType("text/html");
PrintWriter out;
try {
out = response.getWriter();
CommonDAO cmdao=new CommonDAO(ds);
String bmid=request.getParameter("bmid");
ArrayList<Item_Common> elementlist=cmdao.grouplist ( "", bmid , request );
JSONArray array = new JSONArray();
if(elementlist.size()>0){
for (int i = 0; i < elementlist.size(); i++) {
JSONObject object = new JSONObject();
try {
object.put("id", elementlist.get(i).getGetid());
object.put("name", elementlist.get(i).getGetname());
array.put(object);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
JSONObject object = new JSONObject();
try {
object.put("users", array);
} catch (JSONException e) {
e.printStackTrace();
}
out.print(object.toString());
out.flush();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
现在我访问action都出错了。。他不知道跳转到显示页面纠结
我的程序走到 List<Product> li = new ProductDao().findAll(page,pr);
System.out.println(li.toString()); 就不走了。503 505 错误。
var my=function(){
$.ajax({
url:"pr_pageSum",
dataType:"json",
type:"post",
success:function(sum){
i=sum;
$("#s").text(sum);
show(i);
}});
};
//查询所有
var show=function(i){
$("#s").text(i);
var page = $("#p").text();
$.ajax({
url:"pr_findAll",
type:"post",
data:{page:page},
dataType:"json",
success:function(data){
var html="";//用来组装HTML元素
var i=0;//用来存放序号
$.each(data,function(key,value){
i++;
$.each(value,function(k,v){//第二步是取得每个对象的属性值!
if(k=="id")
html+="<tr class='ui-widget-content' id="+v+"><th>"+i+"</th>";
if(k=="pname")
html+="<th>"+v+"</th>";
if(k=="modal")
html+="<th>"+v+"</th>";
if(k=="price")
html+="<th>"+v+"</th>";
if(k=="stockNum")
html+="<th>"+v+"</th>";
if(k=="manufact")
html+="<th>"+v+"</th>";
if(k=="inDate")
html+="<th>"+v+"</th><tr/>";
});
});
$("#selectable").html(html);
}
});
};
但是还是显示不出来数据,,查是查到了数据