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

怕怕哥 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;
}
}

}
...全文
222 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
sirfei 2004-11-16
  • 打赏
  • 举报
回复
报什么错呢
Yujlyjl 2004-11-16
  • 打赏
  • 举报
回复
up
代码下载链接: https://pan.quark.cn/s/cf0000dae7ac 在.NET Framework平台中,`TreeView`组件是一种普遍应用的数据展示工具,主要功能是呈现层级化数据,例如文件系统布局、组织架构图等。本文将深入阐述在C#环境下如何运用递归方法为`TreeView`组件配置子节点,尤其是在管理文件夹层次结构的应用场景中。递归是一种高效的编程策略,其特点在于函数能够自我调用以完成特定任务,这种技术特别适用于处理具有层级关联的数据集合。为了有效运用`TreeView`组件,我们首先需要明确其核心构成单元:`TreeNode`。`TreeNode`是`TreeView`中的一个基本单元,它可以承载子节点,从而构建出树状结构。为了在`TreeView`中准确反映文件夹结构,每一个`TreeNode`通常映射为一个文件夹,而其下属的子节点则对应该文件夹内的子文件夹或文件。现在我们聚焦于核心内容,探讨如何通过递归方式实现子节点的添加。1. **构建基础框架** 我们需要设计一个类来描述文件或文件夹,该类应包含名称、路径等基本属性。例如: ```csharp public class FileSystemItem { public string Name { get; set; } public string Path { get; set; } // 其他属性如IsDirectory等 } ```2. **采集文件系统数据** 借助`System.IO`命名空间中的`DirectoryInfo`和`FileInfo`类,对目标目录进行遍历,以获取所有文件和子文件夹的信息。这里可以利用`GetDirectories()`和`GetFiles...

81,111

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧