从网上看了些,好像都是用了jspsmart这个东西,看他们写的代码jsp页面里好多<% %>,感觉乱糟糟的...请各位指教下,现在能用什么实现jsp中上传图片的功能...若方便的话把代码给我发下,感激不尽!

解决方案 »

  1.   

    有需要 留个邮箱我   我把使用方法连组件一起发给你。  我邮箱:[email protected]
      

  2.   

     写在jsp中不好,在servlet中这样写PrintWriter out;
    try {
    out = response.getWriter();
    out.println("<HTML>");
    out.println("<BODY BGCOLOR='white'>");
    out.println("<H1>jspSmartUpload : Servlet Sample</H1>");
    out.println("<HR>");
    // Variables
    int count = 0;
    SmartUpload mySmartUpload = new SmartUpload(); try {
    // Initialization
    mySmartUpload.initialize(getServlet().getServletConfig(),
    request, response); // Upload
    mySmartUpload.upload(); // Save the file with the original name
    // in a virtual path of the web server
    count = mySmartUpload.save("/img");
    request.setAttribute("imagename", mySmartUpload.getFiles()
    .getFile(0).getFileName());
    // Display the result
    return mapping.findForward("newsAdd2"); } catch (Exception e) {
    out.println("Unable to upload the file.<br>");
    out.println("Error : " + e.toString());
    } out.println("</BODY>");
    out.println("</HTML>"); } catch (IOException e1) {
    e1.printStackTrace();
    }