Wrox Programmer Forums
|
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 May 19th, 2007, 04:29 PM
Registered User
 
Join Date: Apr 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default jstl problem

Hi,

I have a problem in showing a getparameter with name "data".

Now, I wrote my program codes:

file name : ShowContactsServlet.java




import java.io.*;
import java.util.ArrayList;

import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.jasper.tagplugins.jstl.core.ForEach;



import business.ContactBO;

import model.contact;

public class ShowContactsServlet extends HttpServlet {

    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

        ArrayList cList = ContactBO.boInstance.findAll();
        contact[] data = new contact[cList.size()];

        for (int i = 0; i < cList.size(); i++) {

            data[i] = (contact)cList.get(i);

        }




        req.setAttribute("data", data);
        req.getRequestDispatcher("showcontacts.jsp").forwa rd(req, res);


    }

}


File name: showcontacts.jsp


<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ page language="java" contentType="text/html; charset=windows-1256"
    pageEncoding="windows-1256"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
<title>showcontacts</title>
</head>
<body>
<h1>Addressbook-Show Contacts</h1>



<c:forEach items="${data}" var="d" >
    <c:out value="${d.fName}" />
</c:forEach>

......
</body>
</html>


But in runtime I face to this exception:


HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

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

exception

org.apache.jasper.JasperException: Exception in JSP: /showcontacts.jsp:17

14:
15:
16: <c:forEach items="${data}" var="d" >
17: <c:out value="${d.fName}" />
18: </c:forEach>
19:
20: <br/>

or when I use the code "${d.getFName()}" instead of code "${d.fName}" I get the exception below :

org.apache.jasper.JasperException: /showcontacts.jsp(17,1) The function getFName must be used with a prefix when a default namespace is not specified

Now if anybody could help me.
if it's possible for you a bit sooner give the answer of my problem.
thanks every body
bye



 
Old May 22nd, 2007, 12:18 PM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,

What is understood from the code is you are trying to use an object with a name data which you've set as request attribute in your servlet. But n the JSP you forgot to get it and assign it to an object, try to use model.contact[] data = (model.contact[])request.getAttribute("data");

and then try to access it in the forEach tag.

Regards,
Rakesh





Similar Threads
Thread Thread Starter Forum Replies Last Post
JSTL problem winsonkkp JSP Basics 3 August 9th, 2007 03:20 AM
jstl problem vivekkumar_23 Pro JSP 1 May 1st, 2007 04:30 AM
JSTL aadz5 JSP Basics 1 August 8th, 2005 08:26 AM
JSTL files problem wechang JSP Basics 4 June 20th, 2005 03:29 AM
JSTL mrkhairy JSP Basics 5 August 8th, 2003 04:57 PM





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