📄 handle_uploadpic.jsp
字号:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.lang.*,java.io.*,com.jspsmart.upload.*" %>
<%@include file="/db/dbPool.inc"%>
<HTML><HEAD><TITLE>上传图片信息</TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<link href="/lib/main.css" rel="stylesheet" type="text/css">
</head>
<script src="/lib/jsFunc.js"></script>
<jsp:useBean id="queryBean" scope="page" class="Query.Query"/>
<BODY>
<%!
//将字节数组转换成整型或短整型;
private int byteToInt(byte[] b,int length){
int s=0;
length-=1;
for(int i=0;i<length;i++){
if(b[i]>=0)
s=s+b[i];
else
s=s+256+b[i];
s=s*256;
}
if(b[length]>=0)
s=s+b[length];
else
s=s+256+b[length];
return s;
}
%>
<%
SmartUpload su = new SmartUpload();
// 上传初始化
su.initialize(pageContext);
// 上传文件
su.upload();
//int index=su.getFiles().getCount(); //取得上传文件的数目
com.jspsmart.upload.File picFile = su.getFiles().getFile(0);
boolean picType=false,picSize=false,picWidth=false,picHeight=false,colorBit=false;
byte bmpByte[]=new byte[4];
//判断是否为bmp格式;
bmpByte[0]=picFile.getBinaryData(0);
bmpByte[1]=picFile.getBinaryData(1);
if(bmpByte[0]==66 && bmpByte[1]==77)
picType=true;
//判断图片大小;
if(picFile.getSize()==345656)
picSize=true;
//判断图片宽度和高度;
for(int i=0,j=21;i<4;i++,j--)
bmpByte[i]=picFile.getBinaryData(j);
if(byteToInt(bmpByte,4)==480)
picWidth=true;
for(int i=0,j=25;i<4;i++,j--)
bmpByte[i]=picFile.getBinaryData(j);
if(byteToInt(bmpByte,4)==360)
picHeight=true;
//判断图片的颜色位数;
bmpByte[0]=picFile.getBinaryData(29);
bmpByte[1]=picFile.getBinaryData(28);
if(byteToInt(bmpByte,2)==16)
colorBit=true;
/*out.print("格式:"+picType+"<br>");
out.print("大小:"+picSize+"<br>");
out.print("宽度:"+picWidth+"<br>");
out.print("高度:"+picHeight+"<br>");
out.print("颜色位数:"+colorBit+"<br>");*/
if(picType && picSize && picWidth && picHeight && colorBit){
String pID=su.getRequest().getParameter("pID");
String[] bInfo=(su.getRequest().getParameter("bInfo")).split(":");
String bID=bInfo[0];
String wID=bInfo[1];
String sID=bInfo[2];
String wName=bInfo[3];
String tmp_busyNum=bInfo[4];
String oInstr=bInfo[5];
String send_picName=bInfo[6];
String com_pID=bInfo[7];
int isSuc=0;
java.util.Date picTime=new java.util.Date();
//根据数据库已有图片名称,给上传图片赋名;
queryBean.initialize(conn1);
ResultSet rs=queryBean.executeQuery("select max(picName) picName from partsInfo");
rs.next();
String picName=rs.getString("picName");
if(picName==null || picName.equals(""))
picName="00000000";
rs.close();
picName=String.valueOf(Integer.parseInt(picName)+1);
for(int i=picName.length();i<8;i++)
picName="0"+picName;
Statement stmt=conn1.createStatement();
isSuc=stmt.executeUpdate("update partsInfo set picName='"+picName+"',picTime='"+picTime.toLocaleString()+"' where pID='"+pID+"'");
if(isSuc>0){
// 将上传文件全部保存到指定目录
String path=request.getRealPath("/")+"\\uploadFiles\\partPics\\";
//现在所上传的图片都只是bmp的图片;
picName+=".bmp";
picFile.saveAs(path+picName);
%>
<script language="javascript">
successTips("恭喜,您的图片已发布成功!",false,true,"modwInfo.jsp?bID=<%=bID%>&&wID=<%=wID%>&&sID=<%=sID%>&&wName=<%=wName%>&&tmp_busyNum=<%=tmp_busyNum%>&&oInstr=<%=oInstr%>&&picName=<%=send_picName%>&&pID=<%=com_pID%>");
</script>
<%}else{%>
<script language="javascript">
failTips("抱歉,数据插入错误,请重试!",false,true);
</script>
<%}%>
<%}else{%>
<script>
failTips("<font color='#000000'>抱歉,上传图片失败,原因如下:</font><br><%if(!picType) out.print("图片格式必须是bmp格式!<br>");if(!picSize && picWidth && picHeight && picType && colorBit) out.print("该bmp图片必须用X1R5G5B5格式保存!<br>");if(!picWidth || !picHeight) out.print("图片大小必须为480×360!<br>");if(!colorBit) out.print("图片必须是16位色!");%>",false,true);
</script>
<%}%>
</BODY>
</HTML>
<script src="/lib/jsFooter.js"></script>
<%@ include file="/db/dbpoolEnd.inc" %>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -