• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about EL

 
Tang Yue
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given the folowing code within a JSP page


<%
String [] noises = {"moo"};
request.setAttribute("noises",noises);
%>Which of the following will output the word
moo
in the page?

Why ${requestScope.noises} isn't a correct answer? Although noises is an array, can't EL automatically call the toString() of this array?
 
Maneessh saxena
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tang Yue:
Given the folowing code within a JSP page

Why ${requestScope.noises} isn't a correct answer? Although noises is an array, can't EL automatically call the toString() of this array?


It's returning Exactly what's returned by toString() of this array. Instead you can try this ...

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%String name[] = new String[]{"Noisy Place"}; %>
<c:set var="noises" value="<%=name %>" scope="request"/>
It's a ${requestScope.noises[0]}
</body>
</html>

don't forget to include jstl.jar & standard.jar in your classpath.

hope this will help.


Regards
 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No it wont

Result:[Ljava.lang.String;@11bd9c9
${requestScope.noises[0]} will return moo.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic