The Source for Java Technology Collaboration
User: Password:



Brian Leonard

Brian Leonard's Blog

NetBeans - Take 2 and Call Me in the Morning

Posted by bleonard on September 29, 2005 at 06:36 PM | Comments (4)

I came across this post from a frustrated developer today, and couldn't help but wonder - are we keeping NetBeans a secret? Poor Dan is just trying to create a simple JSP. For some reason, I couldn't see the code referenced in his post, but I think I got the gist of what he's trying to do. Let's tackle them one frustration at a time:

Frustration #1 - Create a Hello World Web Project

  1. Create a new Web Application named HelloWorld (File > New Project > Web > Web Application).
  2. Change the text in index.jsp from "JSP Page" to "Hello World!".
  3. Press F6.

Frustration #2 - Closing and Opening a Project

  1. Choose File > Close "HelloWorld"
  2. Choose File > Open Recent Project > HelloWorld

Frustration #3 - Working with JSTL

Here's where I couldn't see Dan's code. However, it looks like he's just trying to display some results from a table. For the purposes of this example, I'm just going to use the Pointbase database and sample data that comes with the J2EE 1.4 SDK. If you already have a different database set up, just change the settings to match your configuration.

  1. Add the Pointbase JDBC driver to the project (Properties > Libraries > Add JAR/Folder). It's in pbembedded.jar, which you'll find in the J2EE SDK's pointbase/lib directory. For me it's at C:\Sun\Appserver\pointbase\lib\pbembedded.jar.
  2. Add the JSTL library to the project (Properties > Libraries > Add Library)
  3. Uncomment the <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> line in index.jsp
  4. Add the line <%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
  5. Add the following between the <body> tags:
<h1>Customer List</h1>
   
 <sql:setDataSource
 var="customerDS"
 driver="com.pointbase.jdbc.jdbcUniversalDriver"
 url="jdbc:pointbase:server://localhost:9092/sample"
 user="pbpublic"
 password="pbpublic"
 />
 
 <sql:query var="customerQuery" dataSource="${customerDS}">
 SELECT * FROM CUSTOMER_TBL
 </sql:query>
 
 <TABLE border=1>
     <TR>
         <TD>Customer Num</TD>
         <TD>Customer Name</TD>
         <TD>Customer City</TD>
         <TD>Customer Phone</TD>
     </TR>
     <c:forEach var="row" items="${customerQuery.rows}">
         <TR>
             <TD><c:out value='${row.CUSTOMER_NUM}'/></TD>
             <TD><c:out value='${row.NAME}'/></TD>
             <TD><c:out value='${row.CITY}'/></TD>
             <TD><c:out value='${row.PHONE}'/></TD>
         </TR>
     </c:forEach>
 </TABLE>    
    
  1. Press Ctrl+Shift+F to reformat the code.
  2. Start Pointbase (Tools > Pointbase Database > Start Local Pointbase Database). Note, you need to have the J2EE 1.4 SDK added as a server to see this option (Tools > Server Manager > Add Server)
  3. Press F6.
result.png

Headache cured.

Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • Thanks for the tips. On a related item, I am a newbie with NetBeans and JSP and I had an issue with JSTL myself, but it was concerning the XML support.

    Whenever I tried to ise the XPath bits in the JSTL, I would get a ClassNotFoundExceptionfor one of the XPath classes - sorry I don't which one.

    How about a simple sample like you did here, but using the XML JSTL?

    Posted by: tyfly on September 30, 2005 at 06:44 AM

  • Sure, I'll put together another example, however, I can probably guess your problem. You're running under Java 5, and with Java 5, the XPath package names changed from "org.apache" to "com.sun.apache". However, the JSTL library is still looking for "org.apache". You have 3 options in this case:

    Run NetBeans under JDK 1.4 (for example "netbeans.exe --jdkhome C:\j2sdk1.4.2_06") which still uses the original "org.apache" package names.
    Add the xalan library to your project (xalan.jar).
    Run the project under the J2EE 1.4 SDK (Sun Java System Application Server 8.1) instead of Tomcat, which already has the xalan.jar in its library.

    Posted by: bleonard on September 30, 2005 at 10:17 AM

  • I've posted the JSTL XML example as promised - More Easy JSTL.

    Posted by: bleonard on September 30, 2005 at 11:40 AM

  • I've posted a follow-up that uses the new palette feature in NetBeans IDE v5.0.

    Posted by: gsporar on October 07, 2005 at 03:17 PM





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds