###前提・実現したいこと
java Servletでmysqlのデータベースへ接続したい.
###発生している問題・エラーメッセージ
https://www.javadrive.jp/servlet/database/index2.html
上記のサイトを参考にmysqlへ接続しようとしています.
Databasetest.javaのコンパイルは成功するのですが,ブラウザで"http://localhost:8080/database/databasetest"にアクセスすると以下のようなエラーが出ます.
Type ステータスレポート メッセージ /database/databasetest 説明 The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
###該当のソースコード
java
1import java.io.*; 2import javax.servlet.*; 3import javax.servlet.http.*; 4 5public class Databasetest extends HttpServlet { 6 7 public void doGet(HttpServletRequest request, HttpServletResponse response) 8 throws IOException, ServletException{ 9 10 response.setContentType("text/html; charset=Shift_JIS"); 11 PrintWriter out = response.getWriter(); 12 13 out.println("<html>"); 14 out.println("<head>"); 15 out.println("<title>データベーステスト</title>"); 16 out.println("</head>"); 17 out.println("<body>"); 18 19 String msg = ""; 20 try { 21 Class.forName("com.mysql.jdbc.Driver").newInstance(); 22 msg = "ドライバのロードに成功しました"; 23 }catch (ClassNotFoundException e){ 24 msg = "ドライバのロードに失敗しました"; 25 }catch (Exception e){ 26 msg = "ドライバのロードに失敗しました"; 27 } 28 29 out.println("<p>"); 30 out.println(msg); 31 out.println("</p>"); 32 33 out.println("</body>"); 34 out.println("</html>"); 35 } 36} 37
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。