首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

跪求解决方案,为什么如何都解决不了啊

2012-03-25 
跪求解决方案,为什么怎么都解决不了啊!!!!!!!!!!我用后台session保存的表格数据。前台获取的session。但现在

跪求解决方案,为什么怎么都解决不了啊!!!!!!!!!!
我用后台session保存的表格数据。前台获取的session。但现在除了个非常严重的问题。那就是session无法及时更新。上网试过各种方法。仍然得不到解决。求各位大能指点迷津啊!!!
  <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<script language="javascript" type="text/javascript" src="jquery-1.6.js"></script>
<%  
response.setHeader( "Pragma ", "No-cache ");  
response.setHeader( "Cache-Control ", "no-cache ");  
response.setDateHeader( "Expires ", 0);  
response.flushBuffer();
%>  

<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css">
.selected {
background: #F57A3F;
color: #FFFFFF;
}
</style>
</head>

<script>
//ajax无刷新效果
var xmlRequest;
//得到请求对象 
function getXMLHttpRequestObject() {
//不同的浏览器创建方式不同
if (window.ActiveXObject) {
xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
xmlRequest = new XMLHttpRequest();
}
return xmlRequest;//返回
}

function getData(flag, id,url) {
//要请求的数据库返回的数据页面

//得到请求对象
xmlRequest = getXMLHttpRequestObject();
if (xmlRequest == null) {
alert("您的浏览器不支持AJAX!");
return;
}

//load 表示是页面加载数据
  if (flag =="select") {
noneTable();
var table=document.getElementById('test');
xmlRequest.onreadystatechange = dataChanged;
xmlRequest.open("POST", url+"?"+Math.random, false);
xmlRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
var count =document.getElementById('count').value
alert(count);
xmlRequest.send(xx); // 发送请求
alert(xmlRequest.responseXML.xml);

}

}

//状态改变 回调函数
function dataChanged() {
if (xmlRequest.readyState == 4) {
alert(xmlRequest.status)
if (xmlRequest.status == 200) {
showDatas();//已经可以正常接受数据
} else { //页面不正常
window.alert("您所请求的页面有异常-1");
}
}
}
//表格部分显示数据
function showDatas(){
//PrintWriter out = response.getWriter();

//从响应页面得到数据
var message = xmlRequest.responseText;
//out.print(message);
alert(message);
//显示数据
//document.getElementById("datadiv").innerHTML = message;

}
</script>
<script type="text/javascript">

</script>
<body>

<form action="/demo/demoselect?operator=toselect" method="post" name="form1" id="form1">
<div style="background: #CCCCCC; float: left; width: 45%">



<table>
<tr>
<td align="center" valign="middle">
查询结果
</td>
<td align="right" valign="middle">
排序:
<input type="hidden" value="null" name="nstore" id="nstore" />
<input type="hidden" value="null" name="nstyle" id="nstyle" />
<select onChange="getData('select','','/demo/demoselect')" name="begintime">
<option value="STYLE_NAME|ASC">
---请选择---
</option>
<option value="STYLE_NAME|ASC">
款型(升)
</option>
<option value="M|ASC">
库存(M升)
</option>
<option value="L|ASC">
库存(L升)
</option>
<option value="XL|ASC">
库存(XL升)
</option>
<option value="M|DESC">
库存(M降)
</option>
<option value="L|DESC">
库存(L降)
</option>
<option value="XL|DESC">
库存(XL降)
</option>
</select>
</td>
</tr>
<%=session.getAttribute("xml")%>

</table>



</div>
</form>
</body>
</html>

------------------------后台代码
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//response.setHeader("Cache-Control", "no-cache, must-revalidate"); 
//response.setContentType("text/xml");
request.setCharacterEncoding("utf-8");
System.out.println("进入查询方法");
//String date=request.getParameter("date");
//System.out.println("---------------------------------------------"+date);
//PrintWriter out = response.getWriter();
demo1Dao damo=new demo1Dao();
String sql = null;
String select_store=request.getParameter("nstore");
System.out.println(select_store);
String select_style=request.getParameter("nstyle");
System.out.println(select_style);
String style_code=request.getParameter("begintime");
System.out.println(style_code);
select_store="null";
select_style="null";
//System.out.println(select_style.equals(null)==false);
if(select_store.equals("null")&&select_style.equals("null"))
{
if(style_code==null){
sql="select STORE_NAME,TBCLASS_NAME,Style_name,SUM(Case When SIZE_NAME='L' Then STOCK_NUM End) As L, SUM (Case When SIZE_NAME='M' Then STOCK_NUM End) As M,SUM (Case When SIZE_NAME='XL' Then STOCK_NUM End) As XL , SUM(STOCK_NUM)AS COUNT from demo1 GROUP BY STORE_NAME,TBCLASS_NAME,Style_name";
}else 
{
String []param=style_code.split("\\|");
System.out.println(param[0]);
System.out.println(param[1]);
sql="select STORE_NAME,TBCLASS_NAME,Style_name,SUM (Case When SIZE_NAME='L' Then STOCK_NUM End) As L, SUM (Case When SIZE_NAME='M' Then STOCK_NUM End) As M,SUM (Case When SIZE_NAME='XL' Then STOCK_NUM End) As XL , SUM(STOCK_NUM)AS COUNT from demo1 GROUP BY STORE_NAME,TBCLASS_NAME,Style_name Order by "+param[0]+" "+param[1];
}
}else{
if(select_store.equals("none")&&select_style.equals("none"))
{
System.out.println("没有传参数,查询全部");
sql="select STORE_NAME,TBCLASS_NAME,Style_name,SUM(Case When SIZE_NAME='L' Then STOCK_NUM End) As L, SUM (Case When SIZE_NAME='M' Then STOCK_NUM End) As M,SUM (Case When SIZE_NAME='XL' Then STOCK_NUM End) As XL , SUM(STOCK_NUM)AS COUNT from demo1 GROUP BY STORE_NAME,TBCLASS_NAME,Style_name";


}else if((select_style.equals("none")==false)&&(select_store.equals("none")==false))
{
System.out.println("有全部参数");
sql="select STORE_NAME,TBCLASS_NAME,Style_name,SUM(Case When SIZE_NAME='L' Then STOCK_NUM End) As L, SUM (Case When SIZE_NAME='M' Then STOCK_NUM End) As M,SUM (Case When SIZE_NAME='XL' Then STOCK_NUM End) As XL , SUM(STOCK_NUM)AS COUNT from demo1 GROUP BY STORE_NAME,TBCLASS_NAME,Style_name having STORE_NAME='"+select_store+"' and Style_name='"+select_style+"'";
}else if((select_style.equals("none")==false))
{
System.out.println("select_style有参数");
sql="select STORE_NAME,TBCLASS_NAME,Style_name,SUM(Case When SIZE_NAME='L' Then STOCK_NUM End) As L, SUM (Case When SIZE_NAME='M' Then STOCK_NUM End) As M,SUM (Case When SIZE_NAME='XL' Then STOCK_NUM End) As XL , SUM(STOCK_NUM)AS COUNT from demo1 GROUP BY STORE_NAME,TBCLASS_NAME,Style_name having Style_name='"+select_style+"'";
}else if((select_store.equals("none")==false))
{
System.out.println("select_store有参数");
sql="select STORE_NAME,TBCLASS_NAME,Style_name,SUM(Case When SIZE_NAME='L' Then STOCK_NUM End) As L, SUM (Case When SIZE_NAME='M' Then STOCK_NUM End) As M,SUM (Case When SIZE_NAME='XL' Then STOCK_NUM End) As XL , SUM(STOCK_NUM)AS COUNT from demo1 GROUP BY STORE_NAME,TBCLASS_NAME,Style_name having STORE_NAME='"+select_store+"'";
}
}
String sql4="select SIZE_NAME from demo1 group by SIZE_NAME ";
StringBuffer xml=damo.getSql(sql,sql4);
System.out.println(xml);
HttpSession session =request.getSession();
session.setAttribute("xml",xml.toString());
String wxml=damo.getString();
//String wxml="\"<td><select id='province'><option>----请选择----</option><option>款式*</option><option>款式1</option></select></td>\"";
System.out.println(wxml);
session.setAttribute("wxml",wxml.toString() );
}

[解决办法]
页面刷新过后去不到值了,还是一直去不到?
[解决办法]
你是不是用了缓存啊? 必须刷新才能出来效果?
[解决办法]
都用ajax了,还用session存数据啊?那何必用ajax呢,既然用了session,那就用同步方法呗。不用同步,就不用用session了。用JSON吧。
[解决办法]
进action的时候删一次存一次,

热点排行