新人求指导,烦请详解。代码部分1
=====================================================
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.ntt.ozone.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.text.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>数据管理</title>
<style type="text/css">
<!--.STYLERED {
color: #FF0000
}
.STYLE3 {
font-size: 14px;
font-weight: bold;
}
.STYLE4 {
font-size: 14px;
}
-->
</style><script language="javascript" src="calendar.js">  //调用JS代码
</script>
<script language="JavaScript">
function SelectAll()
{ var objAll = document.getElementsByName("selectall");
var objs = document.getElementsByTagName("input");

var i;
for(i = 0; i < objs.length; i++)
{
if(objs[i].name != "selectall"&&objs[i].type == "checkbox")
{
objs[i].checked = objAll[0].checked;
}

}
}function ConfirmDelete() //确认删除
{ if( window.confirm('你想删除此记录?'))
{
return true;
}
else
{
return false;
}
}
function  parseStr1(str){
var strArray=new Array();
var temp;
var i=0;
strArray=str.split(",");
document.search.userLocation.options.length=1;
temp = strArray.length;
for(i=0;i<temp;i+=2){
document.search.userLocation.options.add(new Option(strArray[i],strArray[i+1]));
}
document.search.userLocation.options.length=document.search.userLocation.options.length-1;
}
function feedBack1(){  //获得反馈信息
var k=window.frames("coltr1");
    if(k.div.innerText=="load"&&timeCount<18000) 
    {  
     timeCount=timeCount+1;
        setTimeout("feedBack1()",30);
    }   
    else   
         parseStr1(k.div.innerText);  
}
function setLocation(){
var userid = document.search.userName.options[document.search.userName.options.selectedIndex].value;
if(userid==""){
alert("No user selected!");
return false;
}
var k=window.frames("coltr1");
k.location="control1.jsp?theid="+userid;
k.div.innerText="load";
timeCount=0;
setTimeout("feedBack1()",30);
}function  parseStr(str){
var strArray=new Array();
var temp;
var i=0;
strArray=str.split(",");
document.search.userName.options.length=1;
temp = strArray.length;
for(i=0;i<temp;i+=2){
document.search.userName.options.add(new Option(strArray[i],strArray[i+1]));
}
document.search.userName.options.length=document.search.userName.options.length-1;
// getlocationid()
}function feedBack(){  //获得反馈信息
var k=window.frames("coltr2");
    if(k.div.innerText=="load"&&timeCount<18000) 
    {  
     timeCount=timeCount+1;
        setTimeout("feedBack()",30);
    }   
    else   
         parseStr(k.div.innerText);  
}function getUser(){
var k=window.frames("coltr2");
k.location="control2.jsp";
k.div.innerText="load";
timeCount=0;
setTimeout("feedBack()",30);

}
</script></head>
<body onLoad="getUser();"><%@ include file="title.jsp"%>
<iframe name="coltr1" width="0" height="0" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" src="control1.jsp"></iframe><BR>
<iframe name="coltr2" width="0" height="0" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" src="control2.jsp"></iframe><BR>
<%
request.setCharacterEncoding("UTF-8");
String path=request.getRealPath("/")+ Conf.CONF_FILE_NAME;
ConnDB cdb = new ConnDB(path);
%>
<form name="search" method="post" action="dataManager.jsp">
<table width="800" border="0" align="center" cellpadding="0"
cellspacing="0" class="STYLE4">
<tr> <td height="26"><div align="left">开始时间:</div></td>
<td><div align="left">
  <select name="FromYYYY"
onchange="FromYYYYDD(this.value)">
    
      </select> 
  <select name="FromMM" onChange="FromMMDD(this.value)">
    
      </select> 
  <select name="FromDD">
    
      </select>
  </div></td> <td><div align="left">结束时间:</div></td>
<td><div align="left">
  <select name="ToYYYY" onChange="ToYYYYDD(this.value)">
    
      </select> 
  <select name="ToMM" onChange="ToMMDD(this.value)">
    
      </select> 
  <select name="ToDD">
    
      </select>
  </div></td> </tr>
<tr>
<td><div align="left"><font color="navy">用户:</font> </div></td>
<td><label> 
<div align="left">
  <select id="userName" name="userName" ONCHANGE="setLocation()">
    <option value="">--请选择一个用户--</option>
      </select>
        </div>
</label></td> <td><div align="left"><font color="navy">选择的地址:</font></div></td>
<td><label> 
<div align="left">
  <select id="userLocation" name="userLocation">
    <option value="">--选择地址-- </option>
      </select>  
    </div>
</label></td>
</tr>
<tr>
<td>
  <div align="left">
    <input type="submit" name="Submit" value="搜索">
      </div></td><td colspan="2">&nbsp;</td>
<td><label></label></td>
<td></td>
</tr>
</table>
</form><%

try {
ConnDB connDB = new ConnDB(request.getRealPath("/")
+ Conf.CONF_FILE_NAME); String theuserName = (String) session.getAttribute("username");

//检查当前用户的权限
//check the rank of current user
int userRank = Functions.CheckUserRank(connDB, theuserName); if (userRank != 1) {
out.print("<div align=\"center\">You are Not Administrator!</div>");
response.sendRedirect("../index.jsp");
}
String currentPage = request.getParameter("page");
String searchFromYYYY = request.getParameter("FromYYYY");
String searchFromMM = request.getParameter("FromMM");
String searchFromDD = request.getParameter("FromDD");
String searchToYYYY = request.getParameter("ToYYYY");
String searchToMM = request.getParameter("ToMM");
String searchToDD = request.getParameter("ToDD");
String userid = request.getParameter("userName");
String locationid = request.getParameter("userLocation");
StringBuffer sql = new StringBuffer("");
ResultSet rs = null;
int currentPageNo = 1;
int pageNumber = 0;
int recordNumber = 0;
DecimalFormat dformat1 = new DecimalFormat("0.00");
//确定当前页码
//determine the current page num
if (currentPage == null || currentPage.equals("")) {
currentPageNo = 1;
} else {
currentPageNo = Integer.parseInt(currentPage);
}
if (searchFromYYYY == null || searchFromYYYY.equals("")) {
searchFromYYYY = "1900";
}
if (searchFromMM == null || searchFromMM.equals("")) {
searchFromMM = "01";
}
if (searchFromDD == null || searchFromMM.equals("")) {
searchFromDD = "01";
}
if (searchToYYYY == null || searchToYYYY.equals("")) {
searchToYYYY = "2099";
}
if (searchToMM == null || searchToMM.equals("")) {
searchToMM = "12";
}
if (searchToDD == null || searchToDD.equals("")) {
searchToDD = "31";
}

String strFromTime = TimeString.CreateTimeStr(searchFromYYYY,
searchFromMM, searchFromDD, "00", "00", "00");
String strToTime = TimeString.CreateTimeStr(searchToYYYY,
searchToMM, searchToDD, "23", "59", "59"); String strCompactFromTime = TimeString
.TimeStrToCompactStr(strFromTime);
String strCompactToTime = TimeString
.TimeStrToCompactStr(strToTime);

解决方案 »

  1.   

    代码部分2:
    ============================================
    if (userRank != 1) {
    out
    .print("<div align=\"center\">You are Not Administrator!</div>");
    response.sendRedirect("../index.jsp");
    } else {
    //获取记录数
    //get the number of records
    sql = new StringBuffer("");
    if((userid!=null&&userid!="")&&(locationid!=null&&locationid!=""))
    {
    int user_id = Integer.parseInt(userid);
    int location_id= Integer.parseInt(locationid);
         sql.append("SELECT count(*) from picture,user,userlocation where user.id = '"+user_id+"' and userlocation.id = '"+location_id+"' and user.id = userlocation.user_id and userlocation.id = picture.userlocation_id and user.id = picture.user_id and picture_time>'"+strFromTime+"' and picture_time<'"+strToTime+"' ORDER BY picture.picture_time");
    rs = connDB.executeQuery(sql.toString());
    }
    if(userid==null||userid==""){

              sql.append("SELECT count(*) from picture,user,userlocation where user.id = userlocation.user_id and userlocation.id = picture.userlocation_id and user.id = picture.user_id and picture_time>'"+strFromTime+"' and picture_time<'"+strToTime+"' ORDER BY picture.picture_time");           
    rs = connDB.executeQuery(sql.toString());
    }
    if((userid!=null&&userid!="")&&(locationid==null||locationid=="")){
    int user_id = Integer.parseInt(userid);
             sql.append("SELECT count(*) from picture,user,userlocation where user.id = '"+user_id+"' and  user.id = userlocation.user_id and userlocation.id = picture.userlocation_id and user.id = picture.user_id and picture_time>'"+strFromTime+"' and picture_time<'"+strToTime+"' ORDER BY picture.picture_time");
    rs = connDB.executeQuery(sql.toString());
    } /*
     out.print("<br/>");
     out.print(sql);
     out.print("<br/>");
     */
    if (rs != null) {
    if (rs.next()) {
    recordNumber = rs.getInt(1);
    } else {
    recordNumber = 0;
    }
    } else {
    recordNumber = 0;
    }
    //计算总页数
    //compute the number of all pages 
    pageNumber = recordNumber / Conf.RECORDS_PER_PAGE;
    if (recordNumber % Conf.RECORDS_PER_PAGE > 0) {
    pageNumber++;
    }
    if (currentPageNo > pageNumber) {
    currentPageNo = pageNumber;
    }
    if (currentPageNo == 0) {
    currentPageNo = 1;
    } if (recordNumber > 0) {
    Conf conf = new Conf();
    String densitytype = conf.getValue(conf.ADMIN_WEB_DENSITY_TYPE); 
            sql = new StringBuffer("");
    if((userid!=null&&userid!="")&&(locationid!=null&&locationid!=""))
    {
    int user_id = Integer.parseInt(userid);
    int location_id= Integer.parseInt(locationid);
              sql.append("SELECT picture.id picture_id, picture.density1 density1, picture.density2 density2, picture.density3 density3, picture.picture_time time,userlocation.name location_name,user.name user_name from picture,user,userlocation where user.id = '"+user_id+"' and userlocation.id = '"+location_id+"' and user.id = userlocation.user_id and userlocation.id = picture.userlocation_id and user.id = picture.user_id and picture_time>'"+strFromTime+"' and picture_time<'"+strToTime+"' ORDER BY picture.picture_time");
              rs = connDB.executeQuery(sql.toString());
    }
    if(userid==null||userid==""){
              sql.append("SELECT picture.id picture_id, picture.density1 density1, picture.density2 density2, picture.density3 density3, picture.picture_time time,userlocation.name location_name,user.name user_name from picture,user,userlocation where user.id = userlocation.user_id and userlocation.id = picture.userlocation_id and user.id = picture.user_id and picture_time>'"+strFromTime+"' and picture_time<'"+strToTime+"' ORDER BY picture.picture_time");
              rs = connDB.executeQuery(sql.toString());
    }
    if((userid!=null&&userid!="")&&(locationid==null||locationid=="")){
    int user_id = Integer.parseInt(userid);
             sql.append("SELECT picture.id picture_id, picture.density1 density1, picture.density2 density2, picture.density3 density3, picture.picture_time time,userlocation.name location_name,user.name user_name from picture,user,userlocation where user.id = '"+user_id+"' and  user.id = userlocation.user_id and userlocation.id = picture.userlocation_id and user.id = picture.user_id and picture_time>'"+strFromTime+"' and picture_time<'"+strToTime+"' ORDER BY picture.picture_time");
             rs = connDB.executeQuery(sql.toString());
    }
    if ((currentPageNo - 1) * Conf.RECORDS_PER_PAGE == 0) {
    rs.beforeFirst();
    } else {
    rs.absolute((currentPageNo - 1)
    * Conf.RECORDS_PER_PAGE);
    }
    }
    %>
    <form name="delete" method="post" action="deletePic.jsp">
    <table width="800" border="0" align="center" cellpadding="0"
    cellspacing="0">
    <tr>
    <td><label> 
    <div align="left">
      <input type="submit" name="Submit2"
    value="删除" onClick="ConfirmDelete();"> 
        </div>
    </label></td>
    <td>&nbsp;</td>
    </tr>
    </table>
    <table width="800" border="1" align="center" cellpadding="0"
    cellspacing="0" bordercolor="#CCCCCC">
    <tr>
    <td width="38" align="center"><input type="checkbox"
    name="selectall" value="checkbox" onClick="SelectAll()"></td>
    <td width="174" align="center"><span class="STYLE3">时间</span></td>
    <td width="347" align="center"><strong class="STYLE3">地址</strong></td>
    <td width="113" align="center"><strong class="STYLE3">用户</strong></td>
    <td width="116" colspan="3" align="center"><strong class="STYLE3">浓度</strong>
    <div align="center"></div>   </td>
    </tr>
    <%
    for (int i = 0; i < Conf.RECORDS_PER_PAGE
    && recordNumber > 0 && rs.next(); i++) {
    %>
    <tr class="STYLE4">
    <td align="center"><input type="checkbox" name="records"
    value="<%=rs.getString("picture_id")%>"></td>
    <td align="center"><%=rs.getString("time")%></td>
    <td align="center"><%=rs.getString("location_name")%></td>
    <td align="center"><%=rs.getString("user_name")%></td>
    <td align="center"><a
    href="viewPic.jsp?id=<%=rs.getInt("picture_id")%>" target="_blank"><%=dformat1.format(rs.getDouble("density1"))%></a></td>
        <td align="center"><a
    href="viewPic.jsp?id=<%=rs.getInt("picture_id")%>" target="_blank"><%=dformat1.format(rs.getDouble("density1"))%></a></td>
        <td align="center"><a
    href="viewPic.jsp?id=<%=rs.getInt("picture_id")%>" target="_blank"><%=dformat1.format(rs.getDouble("density1"))%></a></td>
    </tr>
    <%
    }

    //为删除数据页面提供参数
    //for delete operation
    session.setAttribute("dmdelfromtime", strCompactFromTime);
    session.setAttribute("dmdeltotime", strCompactToTime);
    session.setAttribute("dmdeluserid", userid);
    session.setAttribute("dmdellocationid", locationid);
    session.setAttribute("dmdelcurrentpage", ""+currentPageNo);
    %>
    </table>
    <br/>
    <%  if(recordNumber==0) out.print("<center><font color=navy>没有查询到相关记录。</font></center>");%>
    <table width="800" border="0" align="center" cellpadding="0"
    cellspacing="0" class="STYLE4">
    <tr align="left">
    <td>| <%
    //分页
    int startPageNo = 0;
    startPageNo = currentPageNo - 5;
    if (startPageNo < 1) {
    startPageNo = 1;
    }
    for (int i = startPageNo; i <= pageNumber
    && i <= startPageNo + 10; i++) { if (i == currentPageNo) {
    out.print("&nbsp;<span class=\"STYLERED\">" + i
    + "</span>&nbsp;|");
    } else {
    out
    .print("&nbsp;<a href=\"dataManager.jsp?userName="
    + userid
    + "&userLocation="
    + locationid
    + "&page="
    + i
    + "&FromYYYY="
    + searchFromYYYY
    + "&FromMM="
    + searchFromMM
    + "&FromFromDD="
    + searchFromDD
    + "&ToYYYY="
    + searchToYYYY
    + "&ToMM="
    + searchToMM
    + "&ToDD="
    + searchToDD
    + "\">"
    + i
    + "</a>&nbsp;|");
    }
    }
    %>
    </td>
    <td>&nbsp;</td>
    </tr>
    </table>
    </form>
    <p>&nbsp;</p>
    <p>&nbsp;</p><%
    }
    } catch (Exception e) {
    ExceptionCollector.doCollect(e, "admin/dataManager.jsp"); }
    %>
    </body>
    </html>
      

  2.   

    看了大半天代码我只想找到你的这个代码 改下试试- -!
     onClick=" return ConfirmDelete();">  
      

  3.   


    <input type="submit" name="Submit2"
    value="删除" onClick="ConfirmDelete();">这个怎么改呢?
      

  4.   

    <input type="submit" name="Submit2" value="删除" onClick="ConfirmDelete();">改成<a href="javascript:ConfirmDelete();">删除</a>function ConfirmDelete() //确认删除  {if( window.confirm('你想删除此记录?'))
      {
        return true; //这里改成document.form***.submit();
      }
    }
      

  5.   

    你直接这样写吧:onClick="window.confirm('你想删除记录吗?')?window.location.href=提交的地址:'空白(点取消的操作)'"
    以下是我写的例子<body>
    <input type="button" value="删除" onClick="window.confirm('你想删除记录吗?')?window.location.href='content.htm':''">
    </body>content.htm<body>
    删除成功!
    </body>当我点取消的时候保持在本页,点确定则跳转到content.htm并显示删除成功!你的代码太长了,我也没细看,不过你好像没有提交,只返回true了吧?
      

  6.   

    <input type="submit" name="Submit2"
    value="删除" onClick="ConfirmDelete();">你是submit按钮,它需要通过true或false,才能控制,而你采用的方式时执行一下,并没有这个返回值。改成这样,试试
    <input type="submit" name="Submit2"
    value="删除" onClick="return ConfirmDelete();">
      

  7.   


    蒽 最后我加了个return 解决的,原来你早就提到了,因为本人菜鸟,所以没看明白,补上感谢哈!