• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSTL and Apache tomcat 7

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
where to download the jstl files needed.I have downloaded jstl-api-1.2.jar and jstl-impl-1.2.jar instead of jstl.jar and standard.jar but they didn't work. And cannot download from "http://tomcat.apache.org/taglibs/standard/"
 
Saloon Keeper
Posts: 7590
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Those are the correct files. What exactly does "it didn't work" mean? Is the web.xml file set up correctly?
 
Sudeep Shakya
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The required output was not displayed, while running the file jdbc.jspx, which should be the same output as the jdbc.jsp

Code for jdbc.jspx is as follows:

<?xml version="1.0" encoding="ISO-8859-1"?>
<jsp:root
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:sql="http://java.sun.com/jsp/jstl/sql"
version="2.1"
>
<jsp:directive.page
language="java"
contentType="ISO-8859-1"
pageEncoding="ISO-8859-1"
/>
<jsp:output
doctype-root-element="html"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
/>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>JDBC/JSTL test</title></head><body>
<sql:setDataSource driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/shop"
user="root" password="root" var="dataSource"
/>
<sql:query var="books" dataSource="${dataSource}">
select * from books
</sql:query>
<table border= "1">
<tr>
<c:forEach var="colName" items="${books.columnNames}">
<td><c:out value="${colName}"/></td>
</c:forEach>
</tr>
<c:forEach var="row" items="${books.rowsByIndex}">
<tr>
<c:forEach var="col" items="${row}">
<td><c:out value="${col}"/></td>
</c:forEach>
</tr>
</c:forEach>
</table>
</body></html>
</jsp:root>


And code for jdbc.jsp is as follows:

<%@page language="java" contentType="text/html"%>
<%@page import="java.sql.*"%>
<html><head><title>JDBC test</title></head><body>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/shop", "root", "root");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from books");
%><table border= "1"><%
ResultSetMetaData resMetaData = rs.getMetaData();
int nCols = resMetaData.getColumnCount();
%><tr><%
for (int kCol = 1; kCol <= nCols; kCol++) {
out.print("<td><b>" + resMetaData.getColumnName(kCol) + "</b></td>");
}
%></tr><%
while (rs.next()) {
%><tr><%
for (int kCol = 1; kCol <= nCols; kCol++) {
out.print("<td>" + rs.getString(kCol) + "</td>");
}
%></tr><%
}
%></table><%
conn.close();
%>
</body></html>
 
Tim Moores
Saloon Keeper
Posts: 7590
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the actual output? What is the desired output? Why are you using the XML JSP notation which is not meant for human processing? And, again, is the web.xml file set up correctly?
 
Sudeep Shakya
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I again tried by reinstalling tomcat and pasting the libraries it worked well. but i don't know what went wrong. Thanks a lot for the reply.
reply
    Bookmark Topic Watch Topic
  • New Topic