[Newbie] Model2 JSP + JDBC + JSTL forEach

Hi,
This is my first post.
I'm running into a bit of brain failure over decoupling my JSP view page from the specifics of the JDBC the model uses.
I want to avoid the easy route of:
Controller
- interogates request as default main listing page.
- runs a JDBC query
- pops the ResultSet in the request
- forwards to the mainlisting.jsp view
JSP View
- Uses a scriplet to iterate and display the contents of the results set as an HTML table.
For a start I don't want to pass a ResultSet to the view page. I'd like to keep it completely ignorant of whether the application is using JDBC, XML or an EJB for it's data tier.
My first smart? idea was to write an adapter for ResultSet that provides a standard List (or similar) interface, taking data from the ResultSet and returning 'domain' value objects instead of Rows.
This presents a secondary problem however. In order to provide a List of beans around the result set I either need to copy the whole result set into an ArrayList or Vector on creation, or implement the entire List interface myself (<yawn>).
So I figured if it's that hard, it can't be the correct way.
Ultimately I'm after some type of Bean collection I can populate (or wrap around) a ResultSet, so that the following JSP will display the list.
<ul>
<c:forEach items="${theListOfItems}" var="item">
<li><c:out value="${item.foo}" /> - <c:out value="${item.bar}" /></li>
</c:forEach>
</ul>
Any pointers?
Cheers
Paul

I'm quite pleased I was on the right track and I even accepted defeat in finding a pipelining way to iterating over the beans attached to the underlying result set and .. as you suggest .. loading it all into beans on creation.
I ended up with this:
package uk.co.cmm.tvrecorder.webapp;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
@SuppressWarnings("serial")
public class RecordingList extends ArrayList<Recording> {
     public RecordingList(ResultSet res) throws SQLException {
          while( res.next() ) {
               Recording rec = new Recording();
               rec.setId(res.getInt("id"));
               rec.setChannel(res.getString("chan"));
               rec.setProgName(res.getString("prog"));
               rec.setPrio(res.getInt("prio"));
               // Date-Times are stored as Unix long ints
               // Why?  Legacy database - allows numerical comparison in legacy dvb recorder shell component.
               // Possible future change to SQL DateTime but not just now.
               Date d = new Date(res.getLong("start")*1000);
               rec.setStart(d);
               d = new Date(res.getLong("stop")*1000);
               rec.setStop(d);
               this.add(rec);
}Which then allowed me to have:
<table>
<tr><th>Programme</th><th>Channel</th><th>Date</th><th>Start</th><th>Stop</th><th>Prio</th></tr>
<c:forEach items="${recordings}" var="item">
     <c:choose>
                 <!-- when is running now -->
          <c:when test="${(now ge item.start) and (now lt item.stop)}">
               <c:set var="style" value="background-color:red;" />
          </c:when>
          <c:otherwise>
               <c:set var="style" value="background-color:white;" />
          </c:otherwise>
     </c:choose>
     <tr style="<c:out value="${style}" />">
          <td><c:out value="${item.progName}" /></td>
          <td><c:out value="${item.channel}" /></td>
          <td><fmt:formatDate type="date" dateStyle="FULL" value="${item.start}"  /></td>          
          <td><fmt:formatDate type="time" value="${item.start}" /></td>          
          <td><fmt:formatDate type="time" timeStyle="LONG" value="${item.stop }" /></td>          
          <td><c:out value="${item.prio}" /></td>     
     </tr>
</c:forEach>That's that sorted, I think.... NEXT!
Is this the correct way to put a var into an HTML attribute?
     <tr style="<c:out value="${style}" />">Cheers
Paul

Similar Messages

  • Newbie question: JSP x JSTL (Will JSTL kill JSP?)

    Hi,
    I'm newbie in java development and know I'm learning about jsp and jstl.
    I'm reading some articles about jstl, but my doubt remains...
    Was jstl create to kill jsp in apresentation layer?
    Please, if possible, show me an example that I really need use jsp instead of jstl?
    What kind of things can't I do with jstl?
    Thanks a lot

    Ranieri wrote:
    I'm sorry, my question wasn't very clear.
    When I said JSP, I wanted say Scriptlet...
    My central point is that Scriptlet is very confortable for me at the moment...
    So, I don't see a motive to change:
    <% if (1 == 2) }....
    to
    <c:if test="1 eq 2">...Lots of motive to change.
    Now... you can say that jstl is more easy, Or you can say that JSTL is easier.
    but if a big number of people start to use it, it will increase and will turn another programming language...It sounds like you think this is a new thing. JSTL has been around for a very long time. 2001 vintage. It's already here, dude.
    Besides, it's not a programming language per se. There will be other tag libraries, but those are custom. JSTL as written hasn't changed in years. The standard won't expand.
    So, why create another programming language if we have Scriptlet to do the same?Like I said before, scriptlets were the mistake. They're unreadable, ugly, and encourage putting logic in JSPs. Very bad, indeed.
    %

  • Newbie with JSP & JDBC questions

    Hi. I have a quick question. I have a client jsp page with a table, listing all the fields from my mySQL table called kellybclients. At the end of each row, I also have a submit button that I would like navigate the user to the campus jsp page that only shows the data associated with the client who's button they clicked on in the table. I'm trying to figure out how to pass this data from my JSP into the rowset.setCommand method in my connection/data bean. I am using a cached row set. Here's the code from my bean:
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package ETS;
    import java.sql.SQLException;
    import javax.sql.rowset.CachedRowSet;
    import java.util.ArrayList;
    import com.sun.rowset.CachedRowSetImpl;
    public class CampusDataBean {
        private CachedRowSet rowSet;
      public CampusDataBean() throws Exception
        Class.forName("com.mysql.jdbc.Driver");
        rowSet = new CachedRowSetImpl();
        rowSet.setUrl("jdbc:mysql://traderseven.nmsu.edu/is470Spring08?relaxAutoCommit=true");
        rowSet.setUsername("is470Spring08");
        rowSet.setPassword("1DoNtier");
        rowSet.setCommand("SELECT campid, clientid, campname,campcounty FROM kellybCampus WHERE clientid=?");
        CampusBean camp = new CampusBean();
        rowSet.setString(1, camp.getClientID());
        rowSet.execute();
      public ArrayList<CampusBean> getCampusList() throws SQLException
        ArrayList<CampusBean> campusList = new ArrayList<CampusBean>();
        rowSet.beforeFirst();
        while(rowSet.next())
          CampusBean campus = new CampusBean();
          campus.setCampID(rowSet.getString(1));
          campus.setClientID(rowSet.getString (2));
          campus.setCampName(rowSet.getString(3));
          campus.setCounty(rowSet.getString(4));
          campusList.add(campus);
        return campusList;
    public void addCampus(CampusBean campus) throws SQLException
        rowSet.moveToInsertRow();
        rowSet.updateString(1,campus.getCampID());
        rowSet.updateString(2,campus.getClientID());
        rowSet.updateString(3,campus.getCampName());
        rowSet.updateString(4,campus.getCounty());
        rowSet.insertRow();
        rowSet.moveToCurrentRow();
        rowSet.acceptChanges();
    }I'm sorry if this is too vague. I'd appreciate any help, fixes, or pointers on where to learn how to do this. Thank you again.
    KellyJo

    So the button should be a Submit button for a form. There are a couple of different methods for doing this:
    1) Each row on the table can be a different form, each form uses the same action (servlet) target and has a hidden input with a unique identifier for each of the clients:
    <table>
      <tr><form action="selectClient" method="post"><td> etc </td><td><input type="hidden" name="id" value="1"/><input type="submit"/></td></form></tr>
      <tr><form action="selectClient" method="post"><td> etc </td><td><input type="hidden" name="id" value="2"/><input type="submit"/></td></form></tr>2) Use a single form with a button type=submit for each row with different values (Note: This is broken in IE7 so you probably shouldn't use it)
    <table><form action="selectClient" method="post">
      <tr><td> etc </td><td><button type="submit" name="id" value="1">Submit</button></td></tr>
      <tr><td> etc </td><td><button type="submit" name="id" value="2">Submit</button></td></tr>3) Use a single form, have a hidden value with a blank value. Each row has a submit button with a javascript onclick method that sets the form's hidden value to one appropriate to the row, then submits the form. I won't show you this code but there are examples on the web.
    4) Use a single form with an input="submit" element on each row. Each button would have a different name with the ID info encoded in it, then you would have server-side code that takes parameters, finds the right one and parses out the proper row to edit:
    <table><form action="selectClient" method="post">
      <tr><td> etc </td><td><input type="submit" name="submit__id_1"/></td></tr>
      <tr><td> etc </td><td><input type="submit" name="submit__id_2"/></td></tr>I think most people end up doing some variant of 3, which I don't like because I hate to rely on JavaScript to make my web apps work properly. I would prefer 4, which takes more work on the server side (which I like better) but 1 works just as well with a lot more typing and uglier HTML code. Actually, I would like 2 the best because that is pretty much what the <button> element was designed for, but Microsoft screwed that up.

  • How to access and display a Web Service from a WSDL in JSP or JSTL ?

    Dear All,
    We need to access a Web Service which is hosted as WSDL How to access a WSDL file from JSP or JSTL, parse and display the SOAP response in JSP page.
    Any simple example or URL as reference to an example will be useful for me.
    It seems io tags of jakarta is able to send soap message, but how to display it in JSP.
    Yours,
    Sankar.B

    Dear Sir,
    Yes. I would like to know more about the Forte and how to consume WSDL file from JSTL. The following are my querirs.
    1. How to connect the declared JNDI from a JSP page. i.e: the Datasource - ex: booksDS
    2. We connect the Tomcat server using JNDI as jdbc/scott. But, if I give jdbc/scott in JSTL as datasource={jdbc/scott}, we could not able to connect. We use the following code in a JSP page to connect the DB from a JSP page. (Its quite easy to modify, so we use the connection in a JSP page.)
    3. How to Consume a WSDL url from JSTL. Ex: If there is a URL : http://localhost/ws/MathService.asmx?wsdl OR http://www.xmethods.com/test/BabelFish
    4. How to display the result. We tried via SOAP from io taglib of Jakarta, but gives us an SOAP (it also looks like xml) response. But, how to use the value from that soap response in IE client thru JSTL/JSP.
    5. Whether this JSTL tool will be available with Forte Enterprise/Community Edition. If so EE, whats the price.
    Please Reply Immediatly. We tried, trying, going to try to display a wsdl response, but not able to display in IE thru JSP/JSTL. But, weve tested the www.gotdotnet.com examples of asp.net web services, we are thru. Its quite easy it seems in .NET. But, we feel whether even there is not even one example in JSTL/ Java Web Services Dev. Pack to utilise a web service in full cycle. The example which uve given is thru servlets. We dont use servlets. Cos, its very easy to edit JSP pages, instead of compiling the serv. and using it.
    I hope ull reply for all the above queries, since ur from SUN.
    Expecting your fav. reply.
    Yours,
    Sankar.B

  • How can i display the values in the vector in a jsp using jstl

    in a task i am recieving a vector in a jsp... how can i display those vector values in the jsp using jstl.... plz help me
    thanks in advance

    <%
    here you got vector say; v
    pagecontext.setAttribute("varname",v);
    %>
    <c:forEach var="i" items="${varname}">
    <c:out value="${i}">
    </c:forEach>

  • JSTL forEach tag taking longer time than scriplets ???

    Hi Gurus,
    My STRUTS action class setsup a collection object [roughly 900 + records stored as java beans] to be displayed on my view [JSP]. The problem is, when I iterate over this collection in JSP using <c:forEach> tag, it takes around 4-5 minutes to build up the page.
    I coded the same looping logic through java scriplets embedded within JSP and the processing came down to 1 minute. Should I assume that <c:forEach> tag will have a processing overhead over plain java code in JSP?
    FYI, I checked the server generated SERVLET code under WORK directory of TOMCAT for this JSP with <c:forEach> tag and find lot of code being generated for this <c:forEach> tag implementation. Could it be that the processing of these generated code takes longer than plain java using scriplets?
    Please Help.
    Thanks,
    Karthik.
    <b>JSP using <c:forEach></b>
    <c:forEach var="refurb" items="${BOMDataForm.refurbSummary}" varStatus="loopStatus">                    
    <tr valign="top" bgcolor="#FFFFFF"> 
    <td>
    <div align="center"><span class="modulecontent"><c:out value="${refurb.configName}" /></span></div>
    </td>                     
    <td>
    <div align="center"><span class="modulecontent"><c:out value="${refurb.itemName}" /></span></div>
    </td>
    </tr>
    </c:forEach><b>JSP using embedded scriplets</b>
    <%
    BOMDataForm bomDataForm = (BOMDataForm) request.getAttribute("BOMDataForm");
    ArrayList arrayList = (ArrayList) bomDataForm.getRefurbSummary();
    int loop = arrayList.size();
    for (int i=0;i<loop;i++) {
    out.println("<tr valign=\"top\" bgcolor=\"#FFFFFF\">");
    out.println("<td>");
    out.println("<div align=\"center\"><span class=\"modulecontent\">");
    out.println(((RefurbSearchResult)arrayList.get(i)).getConfigName());
    out.println("</span></div>");
    out.println("</td>");
    out.println("<td>");
    out.println("<div align=\"center\"><span class=\"modulecontent\">");
    out.println(((RefurbSearchResult)arrayList.get(i)).getItemName());
    out.println("</span></div>");
    out.println("</td>");
    out.println("</tr>");                         
    %>

    Never looked at the speed issues. For me it has always been "fast enough"
    When displaying pages with 900 records on it the common approach is to split the result across multiple pages, so that loading doesn't get too long.
    The JSTL tags obviously introduce some overhead in extra procedure calling. As you found out by looking at the generated servlet code.
    Also the EL expressions have to be evaluated. using the reflection APIs. Its pretty certain that direct access to the object is faster.
    The forEach tag uses an iterator under the hood, where you are calling get(i) directly on an ArrayList.
    Any or all of these would be contributing. My guess would be the EL expression evaluation is probably the most overhead.
    One thing about your example I would like to see is how long it would take using an Iterator, rather than calling get(i) on the array elements. That would remove at least one of the differences.
    So in short, yes the JSTL is adding overhead to your page. I'm a bit surprised to hear it is so much though.
    Cheers,
    evnafets

  • Problem while parsing xmlString in jsp using JSTL

    HI, I am not able to display data in jsp page that I have stored in string variable in XML form.
    I want to print xmlString data in jsp using jstl.
    probably i might have to parse it but i don't have idea . Can any one help me PLZ??

    I managed the code but getting following error
    org.apache.jasper.JasperException: javax.servlet.jsp.JspException: Content is not allowed in prolog.
         org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    root cause
    javax.servlet.ServletException: javax.servlet.jsp.JspException: Content is not allowed in prolog.
         org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:854)
         org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
         org.apache.jsp.xml.test_jsp._jspService(test_jsp.java:106)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    root cause
    org.xml.sax.SAXParseException: Content is not allowed in prolog.
         com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:264)
         com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:292)
         org.apache.taglibs.standard.tag.common.xml.ParseSupport.parseInputSource(ParseSupport.java:227)
         org.apache.taglibs.standard.tag.common.xml.ParseSupport.parseInputSourceWithFilter(ParseSupport.java:193)
         org.apache.taglibs.standard.tag.common.xml.ParseSupport.parseReaderWithFilter(ParseSupport.java:199)
         org.apache.taglibs.standard.tag.common.xml.ParseSupport.parseStringWithFilter(ParseSupport.java:206)
         org.apache.taglibs.standard.tag.common.xml.ParseSupport.doEndTag(ParseSupport.java:138)
         org.apache.jsp.xml.test_jsp._jspx_meth_x_parse_0(test_jsp.java:168)
         org.apache.jsp.xml.test_jsp._jspService(test_jsp.java:82)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

  • Cannot access VARCHAR2s on Oracle 9i using JSP/JDBC

    After upgrading from Oracle 8.1.7 to Oracle 9, I get an
    exception when using JSP/JDBC to read data from columns
    containing VARCHAR2s. I can successfully read columns
    containing BLOBs, CLOBs, NUMBERs, and RAWs.
    I still can select VARCHAR2 columns by using SQL*Plus so the
    problem is with JDBC and not the database.
    I get the following exception message:
    java.sql.SQLException: ORA-00600: internal error code,
    arguments: [ttcgcshnd-1], [0], [], [], [], [], [], []
    The following code that worked on Oracle 8 fails to execute
    properly on Oracle 9:
    OracleResultSet rs = null;
    String sql = "select name from users where id > 100";
    rs = (OracleResultSet)s.executeQuery(sql);
    I'm using Windows 2000, Tomcat 3.2.2, Java 1.3, and the latest
    version of OracleJSP.
    Has anyone run into this problem?
    I've also entered this same query on the Java-SQLJ/JDBC
    discussion fourm.

    I4ve installed Oracle 9i on RedHat 7.2.
    We develop with WebObjects and JBuilder.
    When i try to connect to the database via the EOModeller (JDBC) i got the same error:
    Stack Trace:
    JDBCAdaptorException: ORA-00600: Interner Fehlercode, Argumente: [ttcgcshnd-1], [0], [], [], [], [], [], []
    Then, i started creating and droping tables in the 9i Database >> it works fine.
    Can someone give an solution for this problem??

  • Problem trying to run compile jsp containing JSTL tags

    Hi,
    I am facing a problem regarding compiling jsp containing JSTL tags.
    Can anybody help me out?

    Yes it is giving an error when i try to compile the jsp.
    And it's giving error on the include of the taglib in the jsp as
    C:\dev\ppdev\DOMA\jspcompile\WEB-INF\jstl\c-rt.tld" is an invalid archive file!
    Actually we are not using th default entry for taglib. Instead we have made an entry in the web.xml. Like this
    <taglib>
    <taglib-uri>/WEB-INF/c.tld</taglib-uri>
    <taglib-location>/WEB-INF/jstl/c.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>/WEB-INF/c-rt.tld</taglib-uri>
    <taglib-location>/WEB-INF/jstl/c-rt.tld</taglib-location>
    </taglib>
    And using this uri in the jsp page like this
    <%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
    <%@ taglib uri="/WEB-INF/c-rt.tld" prefix="c_rt" %>
    And when we try to compie the jsp its giving the error.
    C:\dev\ppdev\DOMA\jspcompile\WEB-INF\jstl\c-rt.tld" is an invalid archive file!
    I would appreciate your help and update me if any more information is required.

  • Servlet/jsp/jdbc best approach

    Hello guys
    Which is the best approach when developing servlet/jsp/jdbc? I will take an
    example:
    I have index-page, page2 and page 3.
    When the user writes www.mydomain.com then the page index.jsp checks if the
    user is coming from the servlet, like this:
    <%
    if(request.getAttribute("getPageTitle")==null){
    %>
    <jsp:forward page="/Index" />
    <%
    else{
    %>
    <%@ include file="/include/header.jsp" %>
    content for index.jsp
    <%@ include file="/include/footer.jsp" %>
    <%
    %>
    On the other hand, the Index class has this init()
    public void init(ServletConfig config) throws ServletException {
    super.init(config);
    con = DatabaseConf.getConnection();
    DatabaseConf is a class that handles all the operations related to the
    database.
    Index.class has also the doGet-method like this:
    request.setAttribute ("getPageTitle", "AnyTilte");
    getServletConfig().getServletContext().getRequestDispatcher("/index.jsp").forward(request,
    response);
    Does it looks ok so long?
    Now, I have other pages, page2 and page3 (in fact I have mych more than just
    these, but this is only an example)
    pages.jsp works as index.jsp. It makes a check
    <%
    if(request.getAttribute("getPageTitle")==null){
    %>
    if not satisfied than it redirect to
    <jsp:forward page="/Page2" />
    My concern, however, is about databasemanagement. Even the Page.class has an
    init-method that looks exactly like the one in Index.class, e.g.
    public void init(ServletConfig config) throws ServletException {
    super.init(config);
    con = DatabaseConf.getConnection();
    In conclusion, Im starting jdbc-connection for every class-file that
    initiates. Is this a good approach? What I would like is a solution to
    initiate the database only one time, when the server starts. Not everytime,
    the first time a specially class-file will be called. I know, this will
    happens only one time for a file for the server's lifetime. But Im afraid
    this is not a good way to work.
    Regards
    email2us

    Hello guys
    Which is the best approach when developing
    servlet/jsp/jdbc? I will take an
    example:
    I have index-page, page2 and page 3.
    When the user writes www.mydomain.com then the page
    index.jsp checks if the
    user is coming from the servlet, like this:
    <%
    if(request.getAttribute("getPageTitle")==null){
    %>
    <jsp:forward page="/Index" />
    <%
    else{
    %>
    <%@ include file="/include/header.jsp" %>
    content for index.jsp
    <%@ include file="/include/footer.jsp" %>
    <%
    %>
    On the other hand, the Index class has this init()
    public void init(ServletConfig config) throws
    ServletException {
    super.init(config);
    con = DatabaseConf.getConnection();
    DatabaseConf is a class that handles all the
    operations related to the
    database.
    Index.class has also the doGet-method like this:
    request.setAttribute ("getPageTitle", "AnyTilte");
    getServletConfig().getServletContext().getRequestDispa
    tcher("/index.jsp").forward(request,
    response);
    Does it looks ok so long?
    Now, I have other pages, page2 and page3 (in fact I
    have mych more than just
    these, but this is only an example)
    pages.jsp works as index.jsp. It makes a check
    <%
    if(request.getAttribute("getPageTitle")==null){
    %>
    if not satisfied than it redirect to
    <jsp:forward page="/Page2" />
    My concern, however, is about databasemanagement.
    Even the Page.class has an
    init-method that looks exactly like the one in
    Index.class, e.g.
    public void init(ServletConfig config) throws
    ServletException {
    super.init(config);
    con = DatabaseConf.getConnection();
    Please use the code formatting tags when posting actual code.
    In conclusion, Im starting jdbc-connection for every
    class-file that
    initiates. Is this a good approach? You normally do not want your Servlet to initiate (which I take to mean 'startup') a database. The two can run independently. The place to initiate a database is in your operating system's startup scripts.
    What I would like
    is a solution to
    initiate the database only one time, when the server
    starts. Not everytime,
    the first time a specially class-file will be called.If you are talking about java.sql.Connection, you generally do not want to have a single connection for your entire application. Each thread should use its own connection, or transaction management/logical unit of work will be problematic, at best. You can use a connection pool to improve performance. However, from a caller's perspective, they are receiving a new connection each time.
    I know, this will
    happens only one time for a file for the server's
    lifetime. But Im afraid
    this is not a good way to work.
    Regards
    email2us- Saish

  • API for jsp and jstl

    can any body send URL or help me to download JSP and JSTL API also servlets

    hi,
    Jsp api
    http://tomcat.apache.org/tomcat-5.0-doc/jspapi/index.htmlJstl api
    http://java.sun.com/products/jsp/jstl/1.1/docs/api/index.html

  • Total newbie for jsp..plz help

    frendz...me a total newbie to jsp.havin some problem in it.i have already installed jdk,jwsdp2.0 wif its tomcat container.Already set the path for both ..such as JAVA_HOME=E:\Program Files\Java\jdk1.5.0_06
    TOMCAT_HOME=E:\tomcat50-jwsdp
    and could execute the sample jsp's perfectly.But having problem wif my jsp tutorials. such as when i wrote this counter codes in notepad..
    <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
    <html>
    <head>
    <tittle>Jsp Declaration</tittle>
    </head>
    <body>
    <h1>Declarations</h1>
    <%! int j=0;%>
    <h2>Counter</h2>
    <p>This page has been hit <span> <% ++j %> </span> times since it was first loaded.</p>
    </body>
    </html>
    and i paste it in webapps in tomcat folder.
    What should i do to view the jsp file?isaved as counter.jsp.if i right click and view it in IE/firefox it only shows the source code.is there any mistake in the codes?or i did i do anything wrong?how shall i compile these files?help me aout wif my basics please.thanks bro's..

    "I pasted it in webapps in tomcat folder".
    Webapplications need to go in their own subdirectory inside the webapps directory. Say you want a webapp 'test', then you would store your JSP as
    TOMCAT_DIR\webapps\test\counter.jsp
    Now you can open this JSP in your browser. Assuming Tomcat is running on the localhost and the default port 8080, the url would be:
    http://localhost:8080/test/counter.jsp
    If that doesn't work something is horribly misconfigured.

  • JSTL forEach inside html form

    I am using JSTL to display data in an editable menu. The data is retrieved from a database and the user may change it if required. The problem is that I get a blank page inside the forEach tag.
    %@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <sql:query var="rs" dataSource="jdbc/agenda">
    SELECT * FROM cardapios WHERE username="${pageContext.request.remoteUser}"
    </sql:query>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <form action="../ChangeMenu" method="POST">
    Everything I write here I can see!!!
    <c:forEach var="r" items="${rs.rows}">
    Restaurante: <input type="text" name="restaurante" value="${r.restaurante}" />  I cant see it!!
    Here I have many <input type="text" ..... etc />
    </c:forEach>
    <input type="submit" value="Salvar" />
    </form>
    </body>
    </html>Well, if I remove the form action, it works properly. So, the data is being retrieved from the database.
    Also, do I really have to use <c:forEach> since it will always retrieve just one line from the table? Is there any other way I can get the data from "rs" ?
    Thanks!

    If you know for certain there is exactly one and only ever one row returned, then you can just access it directly:
    <c:set var="r" value="${rs.rows[0]}"/>With regards to the query, it would probably be better using parameter rather than the variable directly:
    <sql:query var="rs" dataSource="jdbc/agenda">
      SELECT * FROM cardapios WHERE username=  ?
      <sql:param value="${pageContext.request.remoteUser}"/>
    </sql:query>I don't think that would change the functionality, but it would prevent SQL injection attacks.
    I don't see how removing the form action would change the display of the html page.
    My suggestion would be to view source on the generated HTML page, and see what is being produced by running the page.
    Did the query return the results that you wanted? Is it generating valid HTML?
    Cheers,
    evnafets

  • Newbie to JSP/Struts: Where to get started

    I would like to begin experimenting with JSP and the struts framework. I'm a java newbie but a relatively quick learner.
    First, what products do I need to use struts/JSP ?
    I have 9iAS standard edition release 1.0.2.1 and an oracle database std edition without the JVM installed. Do I need the JVM in the database ? Can JSP use a JVM outside the database ? Do I need enterprise edition ?
    Do I need Jdevelopper 9i or can I learn to use JSP with simple tools (HTML editor) first ?
    Does struts need JSP 2.0 spec or the JSP 1.1 that comes with iAS 1.0.2.1 is OK ? Is JSP 2.0 = JSP 1.2 (Like J2EE = JDK1.2 and up) There is a lot of version/naming confusion going on in java, you got any site that can help me untangle this mess ?
    Thanks a lot
    You can reply to [email protected]

    Thanks for your response.
    We actually use oracle 8.1.7 and 9iAS (PL/SQL gateway and http server). We would like to jump on the Java Bandwagon before we are left in the dust. We first need to be able to understand a lot of technology/concepts/buzzwords.
    We started basic Java programming (Applications) but would prefer to get an idea of "The big picture".
    By that, I mean, we need to be able to understand/design/architect sound applications and be able to talk to the community and understand what they are saying. Right now, reading the media or forums is just a big bunch of buzzwords that are ever changing and we cannot get a grasp on it.
    We not only need to get aquainted with the concepts, but we also need to be able to determine wether product xyz fits in the architecture, etc...
    If you were to get a couple of good books to answer some questions, where would you begin ?
    Kind of questions we might have are:
    - What is the difference between Jserv and Tomcat ?
    - What excatly is tomcat ? A replacement for Jserv ?
    - Can Jserv be used as a container for struts apps or do you need tomcat ? If you need tomcat, does it come with some version of 9ias ?
    - What is a java web service ?
    - I read a lot about Enterprise Java Beans etc.. What are they, what are there purpose ? It seems like it is a standard, what are they used for ? If it is a standard, does this mean that If I buy a set of EJB from a vendor, it would offer the same beans as another vendor ? Is Oracle BC4J an implementation of EJB with added functionality ? Is it proprietary ?
    - Buzzwords everywhere: MVC, EJB, J2EE, BC4J etc.. What are the definitions.
    - Is oracle's java vision proprietary or are they really following the rest of the world ? For example, is BC4J compatible with EJB ?
    - What is a Framework
    - What exactly is JSP.
    - Can STRUTS be used to access an oracle database ? If so, what are the required components (I guess you need JDBC or SQLJ) but does the oracle database need to be java enabled ?
    - Even if you use oracle 9ias as an application server, can you use non-proprietary development methods/architectures/techniques that could be easily implemented somewhere else using another vendor's application server (Ex: Apache + Tomcat, WebSphere, etc...)
    - Struts seems to be an interesting thing. I see that it was developped to encourage code reuse and prevent everyone from reinventing the wheel. But I cannot understand what exactly a developper had to write before struts was there. I mean, there must be alternatives to strut, if so what is the purpose of the framework ?
    A lot of questions, but we need to understand the basics before we jump on the java bandwagon. If we wait, we'll be left in the dust and we need to keep current.
    Thanks in advance.

  • JSTL forEach

    I am trying to iterate over a Vector of objects. The object is a simple bean with getters and setters called headlinesValue.java. Some attributes are headline, deck, and lead. In my JSP page I want to display some of these attributes. I have a Vector called headlinesLists which contains a number of headlinesValue objects. I tried this:
    <c:forEach items="headlinesLists" var="headlinesValue">
    <a class="digest-headline" href="foo.html"><c:out value="${headlinesValue.headline}" /></a>
    <c:out value="${headlinesValue.deck}" />
    <c:out value="${headlinesValue.lead}" />
    IN LOOP
    </c:forEach>
    but I get a JSP exception:
    javax.servlet.jsp.JspException: An error occurred while evaluating custom action attribute "value" with value "${headlinesValue.headline}": Unable to find a value for "headline" in object of class "java.lang.String" using operator "." (null)
         at org.apache.taglibs.standard.lang.jstl.Evaluator.evaluate(Evaluator.java:146)
    please advise.
    Thank you in advance.
    -Ben

    Check the spelling, capitalization, etc...
    Check to see if your vector named headlinesLists is in a scope that is reachable. That is, if you used scriptlets to create the Vector, did you set it to an attribute in pageContext, request, session, or servletContext?
    Where is the Vector created? Did you set the scope wide enough? Do you have two objects with the same name, one empty used after/in a smaller scope then the filled one?
    Did you put any values in the Vector?
    These are the questions I would ask myself to try and troubleshoot. If you are unsure of the answers, then post the code were you make the Vector.

Maybe you are looking for

  • Error while creating the Organization structure.

    Hi, I am trying to create an Organization structure in SRM 5 sytem, I have created a Root for the structure and when i try to click on the Attribute Inheritance or the Check tab below i am getting an error "Start program BBP_LOCATIONS_GET_ALL first (

  • After upgrading to 8.1 in windows, my ipod is not recognized in computer or itunes

    I upgraded to Windows 8.1 a while back, and just tried to synch my ipod with itunes and now my ipod is not being recognized in my comuper or itunes. Does anyone know why this is and/or how to fix it? Thanks!! Amber

  • Data Selection in Init Infopackage

    Hi All I want to schedule a Delta Upload on a ODS to load data to another ODS For this i created a init load infopackage. I want to give some Data Selections for load. But in the Data Selection Tab I am  unable to see any selection options The same i

  • Screen painter not working with gui 7.1

    Hi, I am using sap gui 7.1 in this im noit able to use screen painter, so im using alphanumeric painter.. I also tried with 6.4 but again same prob So, what could be the problem?

  • Missing controls on the front panel

    Hello, I am improving a GUI and I am having some problem with the Front Panel, I 've seen to be missing some controls: see attachments, please. LabVIEW Intermediate I level! Solved! Go to Solution. Attachments: MissDistancefrontpanel.jpg ‏751 KB Miss