<%@ page contentType="text/html;charset=gb2312"%>
<%@ page language="java" import="com.jspsmart.upload.*"%>
<%@ include file="/inc/sub.jsp"%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
%>
<%@ include file="top.jsp"%>
<%
String newskey="",newstitle="",newsnote="",username="",image1="",image2="",type="",jtime="";
String sqlExec="";
String[] img={"",""};
String disp="";try{ if(se_usergroup.indexOf("u")==-1)
{
response.sendRedirect("worker_err.jsp");
} username=se_userloginname;
jtime=injtime;
// Variables
int count=0; // Initialization
mySmartUpload.initialize(pageContext);
mySmartUpload.setTotalMaxFileSize(5000000);
// Upload
mySmartUpload.upload();
//get Parameter mySmartUpload.getRequest().getParameter()
newskey=(String)mySmartUpload.getRequest().getParameter("newskey");
newstitle=(String)mySmartUpload.getRequest().getParameter("newstitle");
newsnote=(String)mySmartUpload.getRequest().getParameter("newsnote");
type=(String)mySmartUpload.getRequest().getParameter("type"); // Select each file
for (int i=0;i<mySmartUpload.getFiles().getCount();i++){
// Retreive the current file
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i); // Save it only if this file exists
if (!myFile.isMissing()) { // Save the files with its original names in a virtual path of the web server
//myFile.saveAs("/upload/" + myFile.getFileName());
myFile.saveAs("/upload/"+long_time+i+"."+myFile.getFileExt());
img[i]=long_time+i+"."+myFile.getFileExt();
//out.println(img[i]);
// myFile.saveAs("/upload/" + myFile.getFileName(), mySmartUpload.SAVE_VIRTUAL); // sample with a physical path
// myFile.saveAs("c:\\temp\\" + myFile.getFileName(), mySmartUpload.SAVE_PHYSICAL); // Display the properties of the current file
//out.println("FieldName = " + myFile.getFieldName() + "<BR>");
//out.println("Size = " + myFile.getSize() + "<BR>");
//out.println("FileName = " + myFile.getFileName() + "<BR>");
//out.println("FileExt = " + myFile.getFileExt() + "<BR>");
//out.println("FilePathName = " + myFile.getFilePathName() + "<BR>");
//out.println("ContentType = " + myFile.getContentType() + "<BR>");
//out.println("ContentDisp = " + myFile.getContentDisp() + "<BR>");
//out.println("TypeMIME = " + myFile.getTypeMIME() + "<BR>");
//out.println("SubTypeMIME = " + myFile.getSubTypeMIME() + "<BR>"); count ++; } } // Display the number of files which could be uploaded
//out.println("<BR>" + mySmartUpload.getFiles().getCount() + " files could be uploaded.<BR>"); // Display the number of files uploaded
//out.println(count + " file(s) uploaded.");
for(int j=0;j<2;j++)
if(img[j]==null){img[j]="";}
sqlExec="insert into oanews (newskey,newstitle,newsnote,username,type,jtime,image1,image2) values('"+newskey+"','"+newstitle+"','"+newsnote+"','"+username+"','"+type+"','"+injtime+"','"+img[0]+"','"+img[1]+"')";
mysql.Exec(dbURL,dbUser,dbPwd,sqlExec);
disp="<meta HTTP-EQUIV=\"refresh\" CONTENT=\"1;URL=news.jsp\">";
}
catch(Exception e)
{
response.sendRedirect("system_err.jsp");
}
%> <p align=center><font color=red>处理完成,数据更新中,请稍候...</a></p>
<%@ include file="di.jsp"%>
<%=disp%>
<%@ page language="java" import="com.jspsmart.upload.*"%>
<%@ include file="/inc/sub.jsp"%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
%>
<%@ include file="top.jsp"%>
<%
String newskey="",newstitle="",newsnote="",username="",image1="",image2="",type="",jtime="";
String sqlExec="";
String[] img={"",""};
String disp="";try{ if(se_usergroup.indexOf("u")==-1)
{
response.sendRedirect("worker_err.jsp");
} username=se_userloginname;
jtime=injtime;
// Variables
int count=0; // Initialization
mySmartUpload.initialize(pageContext);
mySmartUpload.setTotalMaxFileSize(5000000);
// Upload
mySmartUpload.upload();
//get Parameter mySmartUpload.getRequest().getParameter()
newskey=(String)mySmartUpload.getRequest().getParameter("newskey");
newstitle=(String)mySmartUpload.getRequest().getParameter("newstitle");
newsnote=(String)mySmartUpload.getRequest().getParameter("newsnote");
type=(String)mySmartUpload.getRequest().getParameter("type"); // Select each file
for (int i=0;i<mySmartUpload.getFiles().getCount();i++){
// Retreive the current file
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i); // Save it only if this file exists
if (!myFile.isMissing()) { // Save the files with its original names in a virtual path of the web server
//myFile.saveAs("/upload/" + myFile.getFileName());
myFile.saveAs("/upload/"+long_time+i+"."+myFile.getFileExt());
img[i]=long_time+i+"."+myFile.getFileExt();
//out.println(img[i]);
// myFile.saveAs("/upload/" + myFile.getFileName(), mySmartUpload.SAVE_VIRTUAL); // sample with a physical path
// myFile.saveAs("c:\\temp\\" + myFile.getFileName(), mySmartUpload.SAVE_PHYSICAL); // Display the properties of the current file
//out.println("FieldName = " + myFile.getFieldName() + "<BR>");
//out.println("Size = " + myFile.getSize() + "<BR>");
//out.println("FileName = " + myFile.getFileName() + "<BR>");
//out.println("FileExt = " + myFile.getFileExt() + "<BR>");
//out.println("FilePathName = " + myFile.getFilePathName() + "<BR>");
//out.println("ContentType = " + myFile.getContentType() + "<BR>");
//out.println("ContentDisp = " + myFile.getContentDisp() + "<BR>");
//out.println("TypeMIME = " + myFile.getTypeMIME() + "<BR>");
//out.println("SubTypeMIME = " + myFile.getSubTypeMIME() + "<BR>"); count ++; } } // Display the number of files which could be uploaded
//out.println("<BR>" + mySmartUpload.getFiles().getCount() + " files could be uploaded.<BR>"); // Display the number of files uploaded
//out.println(count + " file(s) uploaded.");
for(int j=0;j<2;j++)
if(img[j]==null){img[j]="";}
sqlExec="insert into oanews (newskey,newstitle,newsnote,username,type,jtime,image1,image2) values('"+newskey+"','"+newstitle+"','"+newsnote+"','"+username+"','"+type+"','"+injtime+"','"+img[0]+"','"+img[1]+"')";
mysql.Exec(dbURL,dbUser,dbPwd,sqlExec);
disp="<meta HTTP-EQUIV=\"refresh\" CONTENT=\"1;URL=news.jsp\">";
}
catch(Exception e)
{
response.sendRedirect("system_err.jsp");
}
%> <p align=center><font color=red>处理完成,数据更新中,请稍候...</a></p>
<%@ include file="di.jsp"%>
<%=disp%>
disp="<meta HTTP-EQUIV=\"refresh\" CONTENT=\"1;URL=news.jsp\">";
是用来延时和刷新到新的页面的!
CONTENT=“延时的秒数”
URL=要转向的页面<p align=center><font color=red>处理完成,数据更新中,请稍候...</a></p>就是你要提示的信息!!
简单、快界、适用于大批量的数据库更新、插入、检索等等……
GOOD LUCK!
有问题来MAIL:[email protected]
至于查询完成后自动消失,实现有点难。不过可以估计一下时间,让弹出窗口在N秒后自动关闭。这个代码应该不是很难,写写看吧。
肯定没有问题!!
我的几乎所有项目中的JSP更新页面都这样解决!!!
别忘了多给点分!
:P马上升星星了!!
谢谢
短消息已经收到!
----------------------------
逆风飞翔:
您好!
我是在csdn上问你问题的 wangxin_qaz (常青藤) ,主题为:急!急!急!关于页面刷新过程中出现的问题,如何解决......高分求教我刚刚学习JSP,有很多地方的东西不会,希望向您请教,我会在csdn上给您很多分的 :-)现在有如下几个问题:
1.您写的这种处理方法能否在一个页面内实现?即提示信息页面和显示数据页面是一个页面?查询过程中只显示提示信息,查询结束后,显示查询结果。2.我写的程序原来在一个页面内(查询、显示),姑且称之为页面A,您这段代码的页面为页面B。
则整个过程为在A页面选择查询条件之后,点击“查询”按钮,显示页面B,数据查询结束后,显示页面A。 则检索出来的数据如何传给页面A?(近10000条记录,从4个表中)
我的处理方法是在B页面,把所有的检索出来的数据放在一个Vector中,然后设置为一个session变量。
但是新的问题又出现了,从其他功能页面再进入页面A后,从session中得到的数据为上一次查询的结果。
另外,如何在保存页面A的检索条件?即A->B->A之后,页面A选择的查询条件(各种checkbox,radio button ,text)保持不变?
3.这么多的数据一下显示出来,的确耗费不少时间。我想分页显示处理,但我没有分页的代码,能否提供一点?
-----------------------------
在此进行回复:
1、如果在一个页面实现,这种方法比较复杂,不可取!当然,你也可以通过判断REQUEST来确定是否刷新,但那样很麻烦,程序不可靠!
2、我建议你用3个页面实现!
a.jsp——提供输入和检索的操作接口
b.jsp——缓冲页面,可用我提供给你的代码
c.jsp——显示结果!
3、然后在C.JSP中进行分页
分页代码如下:
<%@ include file="/inc/sub.jsp"%>
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
%><%@ include file="top.jsp"%><%
ResultSet rst;
String sqlSel1="SELECT * from oanews order by id desc";
try{
if(se_usergroup.indexOf("u")==-1)
{
response.sendRedirect("worker_err.jsp");
}
%>
<table width="780" border="0" cellspacing="0" cellpadding="0">
<tr>
<td background="../../images/worker/mid_bg_1.gif">
<table width="780" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="47"> </td>
<td width="118"> </td>
<td width="555"> </td>
<td width="60"> </td>
</tr>
<tr>
<td> </td>
<td align="center"><a href="../worker/worker_shenhe.jsp"><img src="../../images/worker/left_work.gif" width="80" height="29" border="0"></a></td>
<td> </td>
<td> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td background="../../images/worker/mid_bg_2.gif">
<table width="780" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="47"> </td>
<td width="118"> </td>
<td width="555"> </td>
<td width="60"> </td>
</tr>
<tr>
<td> </td>
<td align="center"><a href="../search/search.jsp"><img src="../../images/worker/left_jstj.gif" width="80" height="29" border="0"></a></td>
<td> </td>
<td> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td background="../../images/worker/mid_bg_3.gif">
<table width="780" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="47"> </td>
<td width="118"> </td>
<td width="555"> </td>
<td width="60"> </td>
</tr>
<tr>
<td> </td>
<td align="center"><img src="../../images/worker/left_system.gif" width="80" height="29"></td>
<td align="center" rowspan=2>
<%
int intPageSize;//一页显示的记录数
int intRowCount;//记录总数
int intPageCount=0;//总页数
int intPage;//待显示页码
java.lang.String strPage; int i; //设置一页显示的记录数
intPageSize = 1; //取得待显示页码
strPage = request.getParameter("page");
if(strPage==null){//表明在QueryString中没有page这一个参数,此时显示第一页数据
intPage = 1;
}
else{//将字符串转换成整型
intPage = java.lang.Integer.parseInt(strPage);
if(intPage<1) intPage = 1;
}
//数据库操作
try{ rst=mysql.Sele(dbURL,dbUser,dbPwd,sqlSel1);
//获取记录总数
rst.last();
intRowCount = rst.getRow();
//记算总页数
intPageCount=(intRowCount+intPageSize-1)/intPageSize;
//调整待显示的页码
if(intPage>intPageCount) intPage = intPageCount;
%>
<form name="form1" method="post" action="">
<p align=center><b> 新闻及公告管理</b></p>
<p align=right><a href=news_add.jsp><font color=blue>添加信息>> </font></a></p>
<table width="530" border="0" cellspacing="1" cellpadding="2" bgcolor="#333333">
<tr>
<td align="center" bgcolor="#CCCCCC" width="50">序号</td>
<td align="center" bgcolor="#CCCCCC" align="center">标题</td>
<td align="center" bgcolor="#CCCCCC">类型</td>
<td align="center" bgcolor="#CCCCCC">添加人</td>
<td align="center" bgcolor="#CCCCCC">删除</td>
<td bgcolor="#CCCCCC" align="center" width="100">注册时间</td>
</tr>
<%
if(intPageCount>0){
//将记录指针定位到待显示页的第一条记录上
rst.absolute((intPage-1) * intPageSize + 1); //显示数据
i = 0;
while(i<intPageSize && !rst.isAfterLast()){
%>
<tr>
<td align="center" bgcolor="#CCCCCC" height="30"> <%=(i+1)%></td>
<td align="center" bgcolor="#FFFFFF"> <a href=news_xiang.jsp?id=<%=rst.getString(1)%> class=news><font color=blue><%=rst.getString(3)%></font></a></td>
<td align="center" bgcolor="#FFFFFF" class=news> <%if(rst.getString(8)!=null && rst.getString(8).equals("1")){%><font color=blue>新闻</font><%}else{%><font color=red>通告</font><%}%></td>
<td align="center" bgcolor="#FFFFFF"> <font color=red><%if(rst.getString(5)!=null){%><%=rst.getString(5)%><%}%></font></td>
<td align="center" bgcolor="#FFFFFF"> <a href=news_del.jsp?id=<%=rst.getString(1)%> class=news><font color=red>删除</font></a></td>
<td align="center" bgcolor="#CCCCCC" align="center" width="100"> <%if(rst.getString(9)!=null){%><%=rst.getString(9).substring(0,10)%><%}%></td></tr> <%
if(rst.isLast()){rst.afterLast();}
rst.next();
i++;
}
}
}catch(Exception e)
{
e.printStackTrace();
}
%>
</table>
</form>
<font color="#FF6600">第<%=intPage%>页 共<%=intPageCount%>页</font> <%if(intPage<intPageCount){%><a href="news.jsp?page=<%=intPage+1%>"><font color="#FF6600">下一页</font></a><%}%> <%if(intPage>1){%><a href="news.jsp?page=<%=intPage-1%>"><font color="#FF6600">上一页</font></a><%}%>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td valign="top">
<table width="118" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="20">>> </td>
<td><a href="../admin/my.jsp" class="news">我的资料</a></td>
</tr>
<tr>
<td height="20">>></td>
<td><a href="../admin/com.jsp" class="news">企业用户管理</a></td>
</tr>
<tr>
<td height="20">>> </td>
<td><a href="../admin/oa.jsp" class="news">内部用户管理</a></td>
</tr>
<tr>
<td height="20">>> </td>
<td><a href="../admin/news.jsp" class="news">新闻及公告管理</a></td>
</tr>
<tr>
<td height="20">>> </td>
<td><a href="../admin/logs.jsp" class="news">日志管理</a></td>
</tr>
</table>
</td>
<td valign="top"> </td>
<td> </td>
</tr>
</table>
</td>
</tr>
</table>
<%}
catch(Exception e)
{
response.sendRedirect("system_err.jsp");
}
%> <%@ include file="di.jsp"%>
while(){}
循环中的
if(rst.isLast()){rst.afterLast();}
判断非常重要!!
有的版本的JDBC当数据库指针到达最后一条记录时,不会因为next()方法而移动到aferLast!!!
所以要判断并手动设置!
for( int i = 0; i < 20; i++ ) //每页显示20条记录
{
int j = (iPage - 1) * 20 + i; //iPage为待显示页码; Object objBookData = vtBookData.get(j); // vtBookData为Vector类型变量;
String [] sBookData = (String [])objBookData;
%> <tr bgcolor="#FFFFFF">
<td height="20"><div align="center"><%=sBookData[0]%></div></td>
<td height="20"><div align="center"><%=sBookData[1]%></div></td>
<td height="20"><div align="center"><%=sBookData[2]%></div></td>
<td><div align="center"><%=sBookData[3]%></div></td>
<td><div align="center"><%=sBookData[4]%></div></td>
<td><div align="center"><%=sBookData[5]%></div></td>
<td><div align="center"><%=sBookData[6]%></div></td>
</tr>
<%
}
%>另外,我们公司做项目的时候,有个不成文的约定:尽量使数据与界面(页面)分离。所有和数据库交互的代码,都写在Bean(或类)的函数里,调用时只输入参数即可。这样代码修改起来也比较方便,算是做项目的一点小小心得吧。