Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 19th, 2007, 04:29 PM
Registered User
 
Join Date: Apr 2007
Location: , , .
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



Reply With Quote
  #2 (permalink)  
Old May 22nd, 2007, 12:18 PM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:43 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.