⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 upload.jsp

📁 网站名称:网上商店 编写语言:JSP 后台数据库:oracle 运行环境平台:安装windows XP sp2 的PC机; 安装了oracle数据库; 安装了Tomcat 5.5 用户
💻 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 + -