?? upload.jsp
字號:
<%@ page language="java" contentType="text/html;charset=gb2312" import="java.sql.*,java.io.*"%>
<%@ page import="com.jspsmart.upload.*"%>
<jsp:useBean id="db" class="wssd.connectDB" />
<%
ResultSet rs = null;
try
{
SmartUpload su = new SmartUpload();
su.initialize(pageContext);
su.setAllowedFilesList("gif,jpg,jpeg,bmp,JPG,GIF,BMP,JPEG");
su.upload();
//*******************
com.jspsmart.upload.File file = su.getFiles().getFile(0);
if(file.isMissing())
{
throw new Exception();
}
String filename = new String((file.getFileName()).getBytes("GBK"));
String title = new String(((String)su.getRequest().getParameter("title")).getBytes("GBK"));
out.print(title);
String introduction = new String(((String)su.getRequest().getParameter("introduction")).getBytes("GBK"));
String sprice = new String(((String)su.getRequest().getParameter("price")).getBytes("GBK"));
double price = (new Double(sprice)).doubleValue();
String mainpic = filename;
String sql = "select MAX(Id) from wssd_car";
rs = db.executeQuery(sql);
int id = 0;
if(rs.next())
{
id = rs.getInt(1) + 1;
}
String path = request.getRealPath("/pic");
path = path + "\\" + String.valueOf(id);
java.io.File d = new java.io.File(path);
if(!d.exists())
{
d.mkdir();
}
int count = su.save("/pic/"+String.valueOf(id));
mainpic = String.valueOf(id)+"/"+mainpic;
sql = "insert into wssd_car(Id,title,price,introduction,mainPic) values("+id+",'"+title+"',"+price+",'"+introduction+"','"+mainpic+"')";
db.executeUpdate(sql);
//*******************
int pid = 0;
for(int i=1;i<su.getFiles().getCount();i++)
{
rs = null;
file = su.getFiles().getFile(i);
if(file.isMissing())
{
continue;
}
String subpic = new String((file.getFileName()).getBytes("GBK"));
subpic = String.valueOf(id)+"/"+subpic;
sql = "select MAX(Id) from wssd_subshow";
rs = db.executeQuery(sql);
if(rs.next())
{
pid = rs.getInt(1) + 1;
}
sql = "insert into wssd_subshow(id,picid,picaddress) values("+pid+","+id+",'"+subpic+"')";
db.executeUpdate(sql);
}
%>
<script language="javascript">
alert("添加成功");
window.close();
opener.top.loacation.reload();
</script>
<%
}
catch(Exception e)
{
e.printStackTrace();
out.print(e.getMessage());
}
finally
{
try
{
db.closeDB();
rs.close();
}
catch(Exception ee)
{
session.setAttribute("error","1");
session.removeAttribute("username");
}
}
%>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -