0
我有一個問題:錯誤使用電腦時我讀文件JSP頁面上遠程
我有一個要求,表示文件的路徑字符串的進入這個JSP客戶端:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form action="action.jsp" method="post">
Enter NameFile (Excel):<input type="text" name="filename"/><br/>
<input type="submit" value="Submit"/>
<input type="reset" value="Reset" />
</form>
</body>
</html>
現在,當我點擊 「提交」,我有這個頁面JSP:
<%@page import="java.io.ByteArrayOutputStream"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.File"%>
<%@page contentType="text/plain" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/plain; charset=UTF-8">
<title>JSP Page Action</title>
</head>
<body>
<%-- start web service invocation --%><hr/>
<%
String filename = request.getParameter("filename");
File file = new File (filename);
FileInputStream fis = new FileInputStream(file);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
for (int readNum; (readNum = fis.read(buf)) != -1;) {
bos.write(buf, 0, readNum); //no doubt here is 0
}
byte[] bi = bos.toByteArray();
try {
ws.MyWS_Service service = new ws.MyWS_Service();
ws.MyWS port = service.getMyWSPort();
// TODO initialize WS operation arguments here
byte[] inputFile = bi;
// TODO process result here
java.lang.String result = port.mywsmethod(inputFile);
out.println(result);
} catch (Exception ex) {
// TODO handle custom exceptions here
}
%>
<%-- end web service invocation --%><hr/>
</body>
</html>
現在,如果我插入
爲什麼我得到這個錯誤C:\prova.xls
07-Oct-2014 08:55:10.194 SEVERE [http-apr-8080-exec-41] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [jsp] in context with path [/myWS_Client] threw exception [An exception occurred processing JSP page /action1.jsp at line 27
25:
26: File file = new File (filename);
27: FileInputStream fis = new FileInputStream(filename);
28: ByteArrayOutputStream bos = new ByteArrayOutputStream();
Stacktrace:] with root cause
java.io.FileNotFoundException: C:\prova.xls (Impossibile trovare il file specificato)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at java.io.FileInputStream.<init>(FileInputStream.java:101)
at org.apache.jsp.action1_005f1_jsp._jspService(action1_005f1_jsp.java:96)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:335)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:534)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:277)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2381)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2370)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:744)
:
在PC遙控器,我得到這個錯誤?我錯了什麼?我試圖用「//」,「\」,「\」和「/」來寫這條路徑,但我總是得到相同的錯誤。
好的...考慮我想上傳一個文件,將其轉換爲數組字節併發送到我的Web服務...我該怎麼做? – Musich87 2014-10-07 07:27:30
看到這個http://docs.oracle.com/javaee/6/tutorial/doc/glraq.html – 2014-10-07 07:30:58
我看到這個文檔...但我不想上傳文件在服務器上的目的地...我想加載一個文件,只轉換和發送數組字節 – Musich87 2014-10-07 07:37:25