Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
|
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 18th, 2003, 08:55 PM
Registered User
 
Join Date: Aug 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default examples in Chapter 3

I (new to jsp, a unix/oracle admin trying to learn java) am using Tomcat5.0.7 alpha, jdk1.4.2, jstl 1.0.3. I followed the book step by step.

bookDB.jsp (p91-92):
I have to replace
    <td><c:out value="${row.id}" /></td>
    <td><c:out value="${row.title}" /></td>
    <td><c:out value="${row.price}" /></td>
with
    <td>${row.id}</td>
    <td>${row.title}</td>
    <td>${row.price}</td>
otherwise it does not work.

bookDB2.jsp (p94-95)
It does not work for me. I can tell the problem is with the <sql:update>, but don't know how to fix it.
if I take out the <sql:update> part from the following <c:if> code

<c:if test="${param.title != null}">
    <sql:update dataSource="${datasource}">
        insert into book (title, price) values (?, ?)
        <sql:param value="${param.title}" />
        <sql:param value="${param.price}" />
    </sql:update>
</c:if>

and still keep the empty <c:if></c:if>, the jsp at least compiles and runs.

The error code start with (got the same kind of error in bookDB.jsp if using <c:out> tag as the book does):

exception

org.apache.jasper.JasperException: Unable to compile class for JSP
    org.apache.jasper.JspCompilationContext.compile(Js pCompilationContext.java:561)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:300)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:293)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:240)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:856)


root cause

java.lang.IllegalArgumentException: -7
    org.apache.jasper.compiler.SmapStratum$LineInfo.se tOutputLineIncrement(SmapStratum.java:124)
    org.apache.jasper.compiler.SmapStratum.optimizeLin eSection(SmapStratum.java:221)
    org.apache.jasper.compiler.SmapUtil.evaluateNodes( SmapUtil.java:490)
    org.apache.jasper.compiler.SmapUtil.generateSmap(S mapUtil.java:123)
..........



any help would be appreciated,

Shen Huang


 
Old August 23rd, 2003, 03:54 AM
Authorized User
 
Join Date: Aug 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try Tomcat 5.0.9. Remember, it's still alpha.

 - Peter

 
Old August 26th, 2003, 07:53 AM
Authorized User
 
Join Date: Aug 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I too am using tomcat5.0.7 and couldn't compile pp91-92 source. Through checking other web sources, I found I needed to modify the taglib prefixes to get it to compile.

Instead of : <%@ taglib prefix="c" uri="........
                   <%@ taglib prefix="sql" uri="........

I put : <%@ taglib prefix="c_rt" uri="........
                 <%@ taglib prefix="sql_rt" uri="........

with this I could compile. Hope this helps!

 
Old August 26th, 2003, 11:05 AM
Registered User
 
Join Date: Aug 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the suggestions. Based on tips from other folks, I copied all jar files from /commom/lib of a SUN's JWSDP 1.2 installation to my own Tomcat507, and now every piece of code in the book works for me so far(JWSDP1.2 has tomcat5 and JSTL included and proved to be working). I don't see any of the problems posted by other members here regarding JSTL/Tomcat5. Clearly, both JSTL and Tomcat5 are still changing, and there is nothing wrong with book.

 
Old August 27th, 2003, 11:22 PM
Authorized User
 
Join Date: Aug 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Interesting...after 3 days of banging my head on this JSTL/SQL tag example (pp91-92), including changing the tags (see previous post by me, which didn't solve the true problem), upgrading from Tomcat 5.0.7 to 5.0.9, upgrading JSTL taglibs, all without success, I did what RNA5132 did, and copied the JAR files from the latest JWSDP installation (from jwsdp-shared/lib directory actually) into Tomcat's common/lib folder. There was already a "commons-collections" JAR, so I didn't copy in the JSWDP's version, but all others went in without a conflict/overwrite situation. I then set my code back to what the book shows, and it runs great. Whew!!

I think if someone looks closer, the true issue will probably be something with the SQL taglibs (now wondering if I should have copies the mysql-connector-java-3.0.8-bin.jar to the Tomcat/common/lib folder rather than the webapps/myproject/WEB-INF/lib folder ??)...although by JAR filenames, none of the copied files seem to reference sql.

BIG, BIG thanks to RNA5132 for his/her solution, which now has me excited again about working through this book!

 
Old August 31st, 2003, 08:07 AM
Registered User
 
Join Date: Aug 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonathan Dorling
Default

hey all

i'm try to get the jsp page on 91-92 to work and they will not!!

in my lib dir i have: mysql-connector-java-3.0.8-stable-bin.jar, standard.jar and jstl.jar

the error i get is: The server failed to return this URL http://localhost:8080/DataAccess/bookdb.jsp

it is save in C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\DataAccess

i can view other jsp file in that dir!!

this is what my jsp page look like:

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

<sql:setDataSource var="datasource"
        driver="com.mysql.jdbc.Driver"
           url="jdbc:mysql://localhost/publish"
          user="publish" password="wroz" />

<sql:query var="book" dataSource="${datasource}">
  SELECT id, title, price FROM book
</sql:query>
<html>
<head>
<title>A First JSP Database</title>
</head>
<body>
<table border="1">
<tr>
<td>id</td><td>title</td><td>price</td>
</tr>
<c:forEach items="${books.row}" var="row">
<tr>
<td><c:out value="${row.id}" /></td>
<td><c:out value="${row.title}" /></td>
<td><c:out value="${row.price}" /></td>
</tr>
</c:forEach>
</table>
</body>
</html>

thnaks for all ur help

jon d
 
Old August 31st, 2003, 08:08 AM
Registered User
 
Join Date: Aug 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonathan Dorling
Default

i now get this error

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Unable to get connection, DataSource invalid: "java.sql.SQLException: Invalid authorization specification: Access denied for user: '[email protected]' (Using password: YES)"
    org.apache.jasper.runtime.PageContextImpl.handlePa geException(PageContextImpl.java:682)
    org.apache.jsp.bookdb_jsp._jspService(bookdb_jsp.j ava:93)
    org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:136)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:856)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:320)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:293)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:240)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:856)


root cause

javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: Invalid authorization specification: Access denied for user: '[email protected]' (Using password: YES)"
    org.apache.taglibs.standard.tag.common.sql.QueryTa gSupport.getConnection(Unknown Source)
    org.apache.taglibs.standard.tag.common.sql.QueryTa gSupport.doStartTag(Unknown Source)
    org.apache.jsp.bookdb_jsp._jspx_meth_sql_query_0(b ookdb_jsp.java:130)
    org.apache.jsp.bookdb_jsp._jspService(bookdb_jsp.j ava:64)
    org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:136)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:856)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:320)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:293)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:240)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:856)
 
Old September 15th, 2003, 04:29 PM
Registered User
 
Join Date: Sep 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My solution. It may help ...

<%@ taglib prefix="c_rt" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="sql_rt" uri="http://java.sun.com/jstl/sql_rt" %>

<sql_rt:setDataSource var="datasource"
               driver="com.mysql.jdbc.Driver"
               url="jdbc:mysql://localhost/publish"
               user="publish" password="wrox" />

<sql_rt:query var="books" dataSource="${datasource}">
    SELECT id, title, price FROM book
</sql_rt:query>

<html>
    <head>
        <title> A First JSP Database</title>
    </head>
    <body>
        <table border="1">
            <tr>
                           <td>id</td><td>title</td><td>price</td
            </tr>

                 <c_rt:forEach items="${books.rows}" var="row">
            <tr>
                <td>${row.id}</td>
                <td>${row.title}</td>
                <td>${row.price}</td>
            </tr>
                </c_rt:forEach>
        </table>
    </body>
</html>


 
Old October 7th, 2003, 11:59 AM
Registered User
 
Join Date: Oct 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Friends:

Raustin's last post really helped me. I am new to Java/JSP, and still unsure of when to use the c.tld verses c-rt.tld because in Beginning J2EE 1.4 Weaver and Mukhar describe the difference as -rt being for run-time and anything that appears within <% %>, yet here(above) we seem to be using it in EL??? hmmm.

Any ways, I know there have been issues with Beginning JSP 2.0 indicating to user that ${2 + 2} works fine when it always does not, but I did manage to resolve this with the following in my web.xml for that particular webapp:

<web-app xmlns= "http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
version="2.4">


   <welcome-file-list>
    <welcome-file>default.htm</welcome-file>
   </welcome-file-list>
YOUR TAG CODE HERE
</web-app>

Also, make sure to place your MySQL JDBC driver in your tomcat\common\lib folder. Off to SQL server JDBC testing.

Mark









Similar Threads
Thread Thread Starter Forum Replies Last Post
examples raheleh BOOK: Beginning JavaServer Pages 0 October 2nd, 2007 12:17 AM
Chapter 11 Code Examples ablinco BOOK: Professional VB 2005 ISBN: 0-7645-7536-8 0 October 9th, 2006 03:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.