急手的文件上传问题~~~~~~~~!

怕怕哥 2004-09-28 11:59:41
以下代码,不知道哪地方错了,请给予帮助.
// FrontEnd Plus GUI for JAD
// DeCompiled : servletUpload.class
package blue;

import com.jspsmart.upload.Request;
import com.jspsmart.upload.SmartUpload;
import java.io.*;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;

public class uploadimages extends HttpServlet
{

private ServletConfig config;

public uploadimages()
{
}

public void destroy()
{
}

public void doGet(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
throws ServletException, IOException
{
PrintWriter printwriter = httpservletresponse.getWriter();
httpservletresponse.setContentType("text/html;charset=gb2312");

printwriter.println("<HTML>");
printwriter.println("<BODY BGCOLOR='white'>");
printwriter.println("<H1>jspSmartUpload : Servlet Sample</H1>");
printwriter.println("<HR><BR>");
printwriter.println("The method of the HTML form must be POST.");
printwriter.println("</BODY>");
printwriter.println("</HTML>");
}

protected void doPost(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
throws ServletException, IOException
{
PrintWriter printwriter = httpservletresponse.getWriter();
httpservletresponse.setContentType("text/html;charset=gb2312");
String imagesavename=new String();
boolean flag = false;
SmartUpload smartupload = new SmartUpload();
try
{
smartupload.initialize(config, httpservletrequest, httpservletresponse);
smartupload.upload();
java.util.Enumeration e = smartupload.getRequest().getParameterNames();
while (e.hasMoreElements()) {
String key = (String)e.nextElement();
String[] values = smartupload.getRequest().getParameterValues(key);
for(int i = 0; i < values.length; i++) {
if (key.equalsIgnoreCase("uname")) imagesavename=values[i];
}
}

for (int i=0;i<smartupload.getFiles().getCount();i++){
com.jspsmart.upload.File myFile = smartupload.getFiles().getFile(i);
myFile.saveAs(imagesavename);
if (!smartupload.getFiles().getFile(i).isMissing())
{
String str_htm="<html>"+(char)(13)+(char)(10)+
"<head>"+(char)(13)+(char)(10)+
"<title>操作成功</title>"+(char)(13)+(char)(10)+
"</head>"+(char)(13)+(char)(10)+
"<body bgcolor=\"#C0C0C0\">"+(char)(13)+(char)(10)+
"<SCRIPT language=JavaScript>"+(char)(13)+(char)(10)+
"self.close();"+(char)(13)+(char)(10)+
"</SCRIPT>"+(char)(13)+(char)(10)+
"</body>"+(char)(13)+(char)(10)+
"</html>";
printwriter.println(str_htm);
//writeOutput(str_htm,"c:\\inetpub\\wwwroot\\online\\img.htm");*/
}
}
// int i = smartupload.save("/");
// printwriter.println(i + " file uploaded.");
}
catch(Exception exception)
{
printwriter.println("Unable to upload the file.<br>");
printwriter.println("Error : " + exception.toString());
}
printwriter.println("</BODY>");
printwriter.println("</HTML>");
}

public final ServletConfig getServletConfig()
{
return config;
}

public final void init(ServletConfig servletconfig)
throws ServletException
{
config = servletconfig;
}
//流方式写文件
static void writeOutput(String str, String strOutFile) {
try {
FileOutputStream fos = new FileOutputStream(strOutFile);
Writer out = new OutputStreamWriter(fos, "GB2312");
out.write(str);
out.close();
}
catch (IOException e) {
e.printStackTrace();
e.printStackTrace();
}
}
//流方式读文件
static String readInput(String strInFile)//String AppendStr
{
StringBuffer buffer = new StringBuffer();
try {
FileInputStream fis = new FileInputStream(strInFile);
InputStreamReader isr = new InputStreamReader(fis, "GB2312");
Reader in = new BufferedReader(isr);
int ch;
int iCharNum;
iCharNum=0;
while ((ch = in.read())>-1) {
iCharNum += 1;
buffer.append((char)ch);
}
//buffer.append(AppendStr);
in.close();
return buffer.toString();
}
catch (IOException e) {
e.printStackTrace();
return null;
}
}

}
...全文
125 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
sirfei 2004-11-16
报什么错呢
回复
Yujlyjl 2004-11-16
up
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告