File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes JSTL and Apache tomcat 7 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL and Apache tomcat 7" Watch "JSTL and Apache tomcat 7" New topic
Author

JSTL and Apache tomcat 7

Sudeep Shakya
Greenhorn

Joined: Dec 04, 2011
Posts: 3
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/"
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Those are the correct files. What exactly does "it didn't work" mean? Is the web.xml file set up correctly?
Sudeep Shakya
Greenhorn

Joined: Dec 04, 2011
Posts: 3
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"
/>
<jsputput
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><cut value="${colName}"/></td>
</c:forEach>
</tr>
<c:forEach var="row" items="${books.rowsByIndex}">
<tr>
<c:forEach var="col" items="${row}">
<td><cut 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
Rancher

Joined: Sep 21, 2011
Posts: 2408
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

Joined: Dec 04, 2011
Posts: 3
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JSTL and Apache tomcat 7