推荐于2016-03-01
展开全部
你去网上下载一个smartUpload.jar,然后把这个import到你的处理页面或者是Servlet中,例如:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.jspsmart.upload.*" %>
<%@page import="s2jsp.bysj.entity.Product"%>
<%@page import="s2jsp.bysj.dao.ProductDao"%>
<%@page import="s2jsp.bysj.dao.impl.ProductDaoImpl"%><%
SmartUpload su=new SmartUpload();
su.initialize(pageContext);
su.upload();
int count = su.save("/image");
Request req = su.getRequest();
String serialNumber= req.getParameter("serialNumber");
String name=req.getParameter("name");
String brand=req.getParameter("brand");
String model=req.getParameter("model");
String price=req.getParameter("price");
String description=req.getParameter("description");
com.jspsmart.upload.File file = su.getFiles().getFile(0) ;
String picture=file.getFileName();
Product product=new Product();
product.setSerialNumber(serialNumber);
product.setName(name);
product.setBrand(brand);
product.setModel(model);
product.setPrice(price);
product.setPicture(picture);
product.setDescription(description);
ProductDao dao=new ProductDaoImpl();
int res=dao.addProduct(product);
if (res!=1)
{
out.print("<script>alert('添加失败。');location.href='addProduct.html';</script>");
return;
}
out.print("<script>alert('添加成功。');location.href='manageProduct.jsp'</script>");
%>
<%@ page import="com.jspsmart.upload.*" %>
<%@page import="s2jsp.bysj.entity.Product"%>
<%@page import="s2jsp.bysj.dao.ProductDao"%>
<%@page import="s2jsp.bysj.dao.impl.ProductDaoImpl"%><%
SmartUpload su=new SmartUpload();
su.initialize(pageContext);
su.upload();
int count = su.save("/image");
Request req = su.getRequest();
String serialNumber= req.getParameter("serialNumber");
String name=req.getParameter("name");
String brand=req.getParameter("brand");
String model=req.getParameter("model");
String price=req.getParameter("price");
String description=req.getParameter("description");
com.jspsmart.upload.File file = su.getFiles().getFile(0) ;
String picture=file.getFileName();
Product product=new Product();
product.setSerialNumber(serialNumber);
product.setName(name);
product.setBrand(brand);
product.setModel(model);
product.setPrice(price);
product.setPicture(picture);
product.setDescription(description);
ProductDao dao=new ProductDaoImpl();
int res=dao.addProduct(product);
if (res!=1)
{
out.print("<script>alert('添加失败。');location.href='addProduct.html';</script>");
return;
}
out.print("<script>alert('添加成功。');location.href='manageProduct.jsp'</script>");
%>
2013-09-13
展开全部
可以用一个第三方插件 FCKeditor
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-13
展开全部
使用jsp uploadsmart组件吧 无组件上传有点麻烦
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询