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 July 21st, 2003, 11:40 AM
Registered User
 
Join Date: Jul 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 3 problem (bookDB2.jsp)

I have followed the book example but there is an error showed up. Please give me the idea how to solve it. Thanks a lot.

Here is the coding:

<%@ 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="phirun" password="amazon" />

<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>
<sql:query var="books" dataSource="${datasource}">
    select id,title,price from book
</sql:query>

<html>
  <head>
     <title> A first JSP database </title>
  </head>
  <body>
    <form method="post">
    <table border="1">
      <tr>
        <td> id </td>
    <td> title </td>
    <td> price </td>
      </tr>
      <c:forEach items="${books.rows}" 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>
    <tr>
      <td> &nbsp; </td>
      <td> <input type="text" name="title" size="30" /> </td>
      <td> <input type="text" name="price" size="5" /> </td>
    </tr>
    <tr>
       <td colspan="3" align="center">
       <input type="submit" value="Save" />
       </td>
     </tr>

    </table>
</form>
 </body>
 </html>

My JSP is just pull the database which is book database and show book title and price on the page. The user is able to enter the new book title and price then click save to update the database. The browser shows the error when clicking the Save Button as follows: javax.servlet.ServletException: 'dataSource' is null

at org.apache.jasper.runtime.PageContextImpl.handlePa geException(PageContextImpl.java:682)

at org.apache.jsp.helloJSP.bookDB2_jsp._jspService(bo okDB2_jsp.java:122)

at org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:136)

at javax.servlet.http.HttpServlet.service(HttpServlet .java:856)

at org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:320)

at org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:293)

at org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:240)

at javax.servlet.http.HttpServlet.service(HttpServlet .java:856)

at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:286)

at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)

at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:256)

at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:151)

at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:562)

at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:974)

at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:205)

at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:151)

at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:562)

at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:974)

at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:177)

at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:151)

at org.apache.catalina.valves.ErrorDispatcherValve.in voke(ErrorDispatcherValve.java:171)

at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:149)

at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:172)

at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:149)

at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:562)

at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:974)

at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:156)

at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:151)

at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:562)

at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:974)

at org.apache.coyote.tomcat5.CoyoteAdapter.service(Co yoteAdapter.java:203)

at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:637)

at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:488)

at org.apache.tomcat.util.net.TcpWorkerThread.runIt(P oolTcpEndpoint.java:568)

at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:631) at java.lang.Thread.run(Thread.java:536)

What have I done wrong? How to debug this program?



 
Old July 23rd, 2003, 04:09 AM
Registered User
 
Join Date: Jun 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear phirun,

replace ${dataSource} in statement

<sql:update dataSource="${data[u]S</u>ource}">

               as

<sql:update dataSource="${datasource}">.
 
Old July 28th, 2003, 12:59 AM
Registered User
 
Join Date: Jul 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Next time when you have similar problem just retypein everything.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 1 - First JSP is not seen by Tomcat aesposito JSP Basics 1 July 29th, 2004 11:56 AM
Beginning JSP 2.0 chapter 2 Charles Howard JSP Basics 2 May 17th, 2004 12:32 AM
JSP 2.0 p457 errata Chapter 12 newtonian JSP Basics 0 March 10th, 2004 02:04 PM
JSP 2.0 p458 errata Chapter 12 newtonian JSP Basics 0 March 10th, 2004 01:53 PM
JSP 2.0 p459 errata Chapter 12 newtonian JSP Basics 0 March 10th, 2004 01:42 PM





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