当前位置: 技术问答>两个javabean的相互调用问题,各位java高手帮忙.
iis7站长之家
100分,高手请帮忙看看这个javabean
来源: 互联网 发布时间:2017-04-22
本文导语: 我得到一个文件上传的例子,但我不知道该如何设置文件上传到服务器特定的目录去。 main.htm ----------- up.jsp ----------- UpBean.java package up; import java.io.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpS...
我得到一个文件上传的例子,但我不知道该如何设置文件上传到服务器特定的目录去。
main.htm
-----------
up.jsp
-----------
UpBean.java
package up;
import java.io.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletInputStream;
public class UpBean {
public void doUpload(HttpServletRequest request) throws IOException{
PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("Demo.out")));
ServletInputStream in = request.getInputStream();
int i = in.read();
while (i != -1) {
pw.print((char) i);
i = in.read();
}
pw.close();
}
}
能根据这些代码,修改修改,具体给个方案实现调用main.htm(提交后文件保存到服务器c:upfile这个目录下)吗?谢谢
main.htm
-----------
up.jsp
-----------
UpBean.java
package up;
import java.io.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletInputStream;
public class UpBean {
public void doUpload(HttpServletRequest request) throws IOException{
PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("Demo.out")));
ServletInputStream in = request.getInputStream();
int i = in.read();
while (i != -1) {
pw.print((char) i);
i = in.read();
}
pw.close();
}
}
能根据这些代码,修改修改,具体给个方案实现调用main.htm(提交后文件保存到服务器c:upfile这个目录下)吗?谢谢
|
给你一段代码,就是用的japsmart,可以在一个servlet里得到数据流后把它写到一个文件里就行了。
private static Data getHttpRequestData(HttpServletRequest req, HttpServletResponse res, ServletConfig servletConfig)
throws LIException
{
Map map = null;
boolean needWordChange = true;
if("GET".equals(req.getMethod()))
{
if(req.getQueryString() != null)
map = HttpUtils.parseQueryString(req.getQueryString());
else
return null;
} else
if("POST".equals(req.getMethod()))
try
{
if(req.getContentType().indexOf("multipart/form-data") != -1)
{
needWordChange = false;
Hashtable aMap = new Hashtable();
SmartUpload smartUpload = new SmartUpload();
smartUpload.initialize(servletConfig, req, res);
smartUpload.setMaxFileSize(0x4c4b40L);
smartUpload.setTotalMaxFileSize(0x4c4b40L);
smartUpload.upload();
System.out.println("**multipart/form-data: Number of files = " + smartUpload.getFiles().getCount());
System.out.println("**multipart/form-data: Total size(bytes) = " + smartUpload.getFiles().getSize());
int count = smartUpload.getFiles().getCount();
for(int i = 0; i
private static Data getHttpRequestData(HttpServletRequest req, HttpServletResponse res, ServletConfig servletConfig)
throws LIException
{
Map map = null;
boolean needWordChange = true;
if("GET".equals(req.getMethod()))
{
if(req.getQueryString() != null)
map = HttpUtils.parseQueryString(req.getQueryString());
else
return null;
} else
if("POST".equals(req.getMethod()))
try
{
if(req.getContentType().indexOf("multipart/form-data") != -1)
{
needWordChange = false;
Hashtable aMap = new Hashtable();
SmartUpload smartUpload = new SmartUpload();
smartUpload.initialize(servletConfig, req, res);
smartUpload.setMaxFileSize(0x4c4b40L);
smartUpload.setTotalMaxFileSize(0x4c4b40L);
smartUpload.upload();
System.out.println("**multipart/form-data: Number of files = " + smartUpload.getFiles().getCount());
System.out.println("**multipart/form-data: Total size(bytes) = " + smartUpload.getFiles().getSize());
int count = smartUpload.getFiles().getCount();
for(int i = 0; i