0

I'm getting the error HTTP Status 404 with description: The requested resourceis not available. I don't know what's wrong!! I'm using netbeans with MySql Workbench where I've created a schema (spesa) with one table (lista).

<%@page import="java.sql.ResultSetMetaData"%>
<%@page import="java.sql.SQLException"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@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>
    <h1>Lista della spesa</h1>
<%
        Class.forName("com.mysql.jdbc.Driver");

         String dburl = "jdbc:mysql://localhost/spesa?user=spesa&password=spesa";

         Connection con = DriverManager.getConnection(dburl);

         Statement st = con.createStatement();
         String sql = "SELECT voce,data,ordine FROM lista ORDER BY ordine";

         ResultSet res = st.executeQuery(sql);

        out.println ("<table>");

        while (res.next () ) {
            String voce = res.getString("voce");
            Date data = res.getDate("data");
            int ordine = res.getInt("ordine");

            out.println("<tr><td>"
                    + voce + "</td><td>"
                    + data + "</td><td>"
                    + ordine + "</td></tr>");
        }

        out.println ("</table>");


        st.close ();

        con.close ();
    %>
</body>

Norbert
  • 6,026
  • 3
  • 17
  • 40
O.M.
  • 17
  • 1
  • Is Tomcat properly configured to serve your URL? Do you get the same error if your page just has a "Hello, world!"? – Sasha Pachev Nov 27 '15 at 22:20
  • A 404 means that the server can't find the page that's being requested, so posting the page code won't help diagnose the problem. – Mike Baranczak Nov 27 '15 at 23:39
  • What URL are you requesting when you get the 404 error? Let's start with that. – Mike Baranczak Nov 27 '15 at 23:42
  • @MikeBaranczak The requested URL is: localhost:8080/SpesaDB/WEB-INF/index.jsp – O.M. Nov 28 '15 at 12:56
  • The files inside WEB-INF are not meant to be accessed by the client (not directly, anyway). If index.jsp is ins WEB-INF, move it to the directory above that, then remove /WEB-INF from the URL. – Mike Baranczak Nov 28 '15 at 14:27
  • @MikeBaranczak Thank you so much! It worked! But there's a way to do that with index.jsp in web-inf directory? – O.M. Nov 28 '15 at 15:16
  • There are many different ways. The question is *why* do you want to do it? – Mike Baranczak Nov 28 '15 at 18:15
  • @MikeBaranczak It's just curiosity! – O.M. Nov 28 '15 at 19:35
  • If you have a JSP segment that you want to reuse in multiple pages, then you can put it in a file and include the segment file in those pages. Or if you want to do some processing on the request before it gets to the JSP code, you can configure the app to send the request to a servlet, which does its thing then forwards the request to a JSP. In both cases, you don't want users to access the JSP directly, so you put it somewhere in WEB-INF. – Mike Baranczak Nov 28 '15 at 20:21
  • Further reading: http://stackoverflow.com/questions/14580120/whats-the-difference-between-including-files-with-jsp-include-directive-jsp-in – Mike Baranczak Nov 28 '15 at 20:25

0 Answers0