写在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(); }
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();
}