now has been achieved in the java file file upload, download, delete, and view, but the program writes web client (written jsp, bean, servlet in) encountered some problems, I do not know what issues should pay attention to, Please help out.
------ Solution ---------------------------------------- ----
There are many issues that need attention
such as Web load balancing, access high concurrency. Some problems may be unrelated and HADOOP
LZ should encounter specific issues write, analyze specific issues
------ Solution ------------------------------------ --------
Configuration is not set up in fs.default.name
tomcat start at what has gone wrong?
------ For reference only -------------------------------------- -
each file code:
upload.jsp:
<% @ page language = "java" contentType = "text / html; charset = GB18030"
pageEncoding = "GB18030"%>
File Upload
HDFSOperation.java:
package servlet;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
public class HDFSOperation {
private Configuration conf;
private FileSystem fs;
public HDFSOperation () throws IOException {
conf = new Configuration ();
fs = FileSystem.get (conf);
}
public boolean upLoad (String filePath) {
try {
InputStream in = new BufferedInputStream (new FileInputStream (filePath));
fs = FileSystem.get (URI.create ("hdfs :/ / localhost: 9000/text"), conf);
OutputStream out = fs.create (new Path ("hdfs :/ / localhost: 9000/text"));
IOUtils.copyBytes (in, out, 4096, true);
} catch (IOException e) {
e.printStackTrace ();
return false;
}
return true;
}}
uploadServlet.java:
package servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/ **
* Servlet implementation class uploadServlet
* /
@ WebServlet ("/ uploadServlet")
public class uploadServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/ **
* @ see HttpServlet # doPost (HttpServletRequest request, HttpServletResponse response)
* /
protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String filePath = request.getParameter ("filePath");
HDFSOperation hdfsOperation = new HDFSOperation ();
boolean flag = hdfsOperation.upLoad (filePath);
if (flag) {
response.sendRedirect ("success.jsp");
} else {
response.sendRedirect ("failure.jsp");
}
}
}
web.xml:
------ For reference only --------------------------- ------------
upload.jsp at run time, tomcat will not start.
help look at the code, there must be a lot wrong with it.
------ For reference only -------------------------------------- -
please refer upstairs, set fs.default.name
------ For reference only ----------------------- ----------------
downloaded works in another set fs.default.name, and introduced in the original project into their own jar package hadoop jar in the package, and then just fine, thank you help.
------ For reference only -------------------------------------- -
downloaded works in another set fs.default.name, and the introduction of the original project into a jar in his hadoop jar package, and then just fine, thank you help.
------ For reference only -------------------------------------- -
me that a lot of pressure novice Yeah, worship ing
没有评论:
发表评论