Eclipseを勉強中です。
eclipseで実行しています。
動的プロジェクトファイル名SampleServletでsample.htmlを実行すると
ダイアログが出て、
タイトル「ファイルのアップロード」
その下に「参照ボタン」クリック、ファイル選択でファイル(c:\tmp\abcd.txt)を選択して送信すると
エラーが出ます。
//eclipseのコンソールのエラー内容
情報: Server version: Apache Tomcat/9.0.7 [日 5月 13 11:53:50 JST 2018]
情報: Server built: Apr 3 2018 19:53:05 UTC [日 5月 13 11:53:50 JST 2018]
情報: Server number: 9.0.7.0 [日 5月 13 11:53:50 JST 2018]
情報: OS Name: Windows 10 [日 5月 13 11:53:50 JST 2018]
情報: OS Version: 10.0 [日 5月 13 11:53:50 JST 2018]
情報: Architecture: amd64 [日 5月 13 11:53:50 JST 2018]
情報: Java Home: C:\pleiades\pleiades\java\10 [日 5月 13 11:53:50 JST 2018]
情報: JVM Version: 10+46 [日 5月 13 11:53:50 JST 2018]
情報: JVM Vendor: "Oracle Corporation" [日 5月 13 11:53:50 JST 2018]
情報: CATALINA_BASE: C:\pleiades\pleiades\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp1 [日 5月 13 11:53:50 JST 2018]
情報: CATALINA_HOME: C:\pleiades\pleiades\tomcat\9 [日 5月 13 11:53:50 JST 2018]
情報: Command line argument: -Dcatalina.base=C:\pleiades\pleiades\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp1 [日 5月 13 11:53:50 JST 2018]
情報: Command line argument: -Dcatalina.home=C:\pleiades\pleiades\tomcat\9 [日 5月 13 11:53:50 JST 2018]
情報: Command line argument: -Dwtp.deploy=C:\pleiades\pleiades\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps [日 5月 13 11:53:50 JST 2018]
情報: Command line argument: -Dfile.encoding=UTF-8 [日 5月 13 11:53:50 JST 2018]
情報: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\pleiades\pleiades\java\10\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/pleiades/pleiades/eclipse/jre/bin/../jre/bin/server;C:/pleiades/pleiades/eclipse/jre/bin/../jre/bin;C:/pleiades/pleiades/eclipse/jre/bin/../jre/lib/amd64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;c:\Program Files\java\jdk-10.0.1\bin;"C:\Program Files\Java\jdk-10.0.1\bin;";C:\Program Files (x86)\Intel\iCLS Client;C:\Program Files\Intel\iCLS Client;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Users\nakamura\AppData\Local\Microsoft\WindowsApps;;C:\pleiades\pleiades\eclipse;;.] [日 5月 13 11:53:50 JST 2018]
情報: Initializing ProtocolHandler ["http-nio-8080"] [日 5月 13 11:53:50 JST 2018]
情報: Using a shared selector for servlet write/read [日 5月 13 11:53:50 JST 2018]
情報: Initializing ProtocolHandler ["ajp-nio-8009"] [日 5月 13 11:53:50 JST 2018]
情報: Using a shared selector for servlet write/read [日 5月 13 11:53:50 JST 2018]
情報: Initialization processed in 935 ms [日 5月 13 11:53:50 JST 2018]
情報: サービス [Catalina] を起動します [日 5月 13 11:53:50 JST 2018]
情報: Starting Servlet Engine: Apache Tomcat/9.0.7 [日 5月 13 11:53:50 JST 2018]
情報: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. [日 5月 13 11:53:51 JST 2018]
情報: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. [日 5月 13 11:53:51 JST 2018]
情報: Starting ProtocolHandler ["http-nio-8080"] [日 5月 13 11:53:51 JST 2018]
情報: Starting ProtocolHandler ["ajp-nio-8009"] [日 5月 13 11:53:51 JST 2018]
情報: Server startup in 872 ms [日 5月 13 11:53:51 JST 2018]
重大: サーブレット [sample.FileUpload] のServlet.service()が例外を投げました [日 5月 13 11:54:00 JST 2018]
//内部ブラウザhttp://localhost:8080/SampleServlet/sampleのエラー
HTTPステータス 500 - Internal Server Error
Type Exception Report
メッセージ Unable to process parts as no multi-part configuration has been provided
説明 The server encountered an unexpected condition that prevented it from fulfilling the request.
例外
java.lang.IllegalStateException: Unable to process parts as no multi-part configuration has been provided
org.apache.catalina.connector.Request.parseParts(Request.java:2746)
org.apache.catalina.connector.Request.getParts(Request.java:2712)
org.apache.catalina.connector.Request.getPart(Request.java:2875)
org.apache.catalina.connector.RequestFacade.getPart(RequestFacade.java:1105)
sample.SampleServlet.doPost(SampleServlet.java:31)
javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
注意 原因のすべてのスタックトレースは、のログに記録されています
Apache Tomcat/9.0.7
以上です。
SampleServletをeclipseで単独で実行しても以下のエラーになります。
内部ブラウザhttp://localhost:8080/SampleServlet/sampleに
HTTPステータス 405 - Method Not Allowed
Type ステータスレポート
メッセージ HTTPのGETメソッドは、このURLではサポートされていません。
説明 The method received in the request-line is known by the origin server but not supported by the target resource.
Apache Tomcat/9.0.7
よろしくお願いいたします。
// FileUpload/WebContent/sample.html <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>アップロード</title> </head> <body> <h1>ファイルのアップロード</h1> <form action="sample" enctype="multipart/form-data" method="POST"> 入力:<input type="file" size="20" name="fname"> <input type="submit" value="送信"> </form> </body> </html> //SampleServlet/src/sample/SampleServlet.java package sample; import java.io.IOException; import java.io.PrintWriter; import java.util.Date; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.Part; @WebServlet("/sample") public class SampleServlet extends HttpServlet { private static final long serialVersionUID = 1L; public SampleServlet() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { super.doGet(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ServletContext con = this.getServletContext(); Part part = request.getPart("fname"); String fname = "FILE" + new Date().getTime() + ".data"; String disposition = part.getHeader("Content-Disposition"); String[] headers = disposition.split(";"); for (String header : headers) { String str = header.trim(); if (str.startsWith("filename=")) { str = str.substring(10, str.length() - 1); String[] paths = str.split("\\"); fname = paths[paths.length - 1]; } } part.write(fname); response.setContentType("text/html;charset=utf-8"); PrintWriter out = response.getWriter(); out.print("<html><body><h1>アップロードしました。</h1></body></html>"); } }
回答1件
あなたの回答
tips
プレビュー