0

I'm trying to retrieve data from my database with JSP and project them to an html page. I was using servlet scriptlet but found out JSTL is a better way so I went for that. The problem is that when compiled the page does return an error: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

I tried to fetch data from the same database with standard java and it worked... But here it does not. My source code for the specific page is:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@page import="java.sql.*" %>
<%@page import="java.lang.String" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Main Menu</title>
</head>

<style>
    body {
        background-color: lightblue;
    }
</style>

<sql:setDataSource var = "snapshot" driver = "com.mysql.jdbc.Driver"
                   url = "jdbc:mysql://127.0.0.1:3306/CARDATA"
                   user = "toomlg4u"/>

<sql:query dataSource = "${snapshot}">USE CARDATA;</sql:query>

<sql:query dataSource = "${snapshot}" var = "result">
    SELECT * FROM Users;
</sql:query>

<table border = "1" width = "100%">
    <tr>
        <th>ID</th>
        <th>Full Name</th>
        <th>Password</th>
        <th>Email</th>
    </tr>

<c:forEach var = "row" items = "${result.rows}">
    <tr>
        <td> <c:out value = "${row.userId}"/></td>
        <td> <c:out value = "${row.realName}"/></td>
        <td> <c:out value = "${row.userName}"/></td>
        <td> <c:out value = "${row.passWord}"/></td>
        <td> <c:out value = "${row.email}"/></td>
    </tr>
</c:forEach>
</table>

</body>
</html>

Every bit of help is appreciated!

P.S: This is just a small project not something professional.

EDIT

I copied the jconnector over to the lib folder of $CATALINA_HOME, so now it shows the table but without values... and strangely my two queries above...

1 Answer 1

1

You have not imported the taglibs in your file

Add

<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %> 

to the top of your page.

Also your table has 5 columns but only 4 header columns.

You can remove the <%@page import tags as well

Sign up to request clarification or add additional context in comments.

4 Comments

Adding them gives me syntax errors: cannot resolve taglib with uri "...." like that... Also I added the column and now my page displays the problem I first encountered.
What servlet container are you using?
Servlet 4.0 with tomcat 9.0.x
You are probably missing the JSTL jar in your classpath. Either add the jstl jar as a project dependency or add the JSTL jar to the Tomcat lib folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.