This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes call something (set array and get its length ) from include file in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "call something (set array and get its length ) from include file in jsp " Watch "call something (set array and get its length ) from include file in jsp " New topic
Author

call something (set array and get its length ) from include file in jsp

Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
Hello
im kinda newbee to jsp , and Im trying to figure out how to accomplish this :
I have simple page that include second page the main page looks like this :
set.jsp :

<%@ include file="get.jsp" %>
<% Object[] params = new Object[3];%>
<% params[0] = "fo1" ;%>
<% params[1] = "gla" ;%>
<% params[2] = "gg" ;%>
<% request.setAttribute("genericTemplatesOpenDocumentHeadComponentParams",params); %>
<html>
<body>
<% out.println(pl); %>
</body>
</html>

and the include file looks like this :
get.jsp:
<% Object[] paramsHead = (Object[])request.getAttribute("genericTemplatesOpenDocumentHeadComponentParams"); %>
<% int pl = Array.getLength(paramsHead); %>

as you can see im trying to print the length of the array but witout any lock
the error im getting is:

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 4 in the jsp file: /get.jsp
Generated servlet error:
Array cannot be resolved

why is that ?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

paramsHead.length will return the array's length


[My Blog]
All roads lead to JavaRanch
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Originally posted by Meir Yan:

Array cannot be resolved


This says it all. Did you import the package containing Array?

Or, as Satou pointed out, why are you getting the length of the array the hard way?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
what do you mean by the hard why ?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

The easy way : paramsHead.length
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Originally posted by Meir Yan:
what do you mean by the hard why ?


java.lang.reflect.Array.getLength(array)

vs.

array.length

Why would you be using the former?
Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
ok I fixed that and its working fine but now I have some kind of scoping problem
here is what I have :
the include get.jsp :

<% Object[] paramsHead = (Object[])request.getAttribute("genericTemplatesOpenDocumentHeadComponentParams"); %>
<% int j = paramsHead.length; %>
<% String parm_len = Integer.toString(j);%>

and in the main set.jsp page I have :


<%@ include file="get.jsp" %>
<% Object[] params = new Object[3];%>
<% params[0] = "fo1" ;%>
<% params[1] = "gla" ;%>
<% params[2] = "gg" ;%>
<% request.setAttribute("genericTemplatesOpenDocumentHeadComponentParams",params); %>
<html>
<body>
<% out.println(arr_len+"\n"); %>
</body>
</html>

the arr_len can't be read this is what I see in the eclipse debug
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Are you serious? You obviously can't reference a variable that was never created.
Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
sorry sorry , i have to be
<% out.println(parm_len+"\n"); %>
that has bean set in the include page .
and it can't be read.
Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
ok its not variable problem when i changed the code in the include file to
<% int j = 77; %>
<% String parm_len = Integer.toString(j);%>
the main page did print the value 77 to the page , this mean i have problm
white the :
request.getAttribute or request.getAttribute
what can it be ? is there any thing wrong there i can't see?
Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
Ok maybe im doing every thing wrong here , my purpose in the end is to build includes for headers and footers
that takes parameters from the main page and according to that will present the relevant data , is that the way to do that?
can someone please ponit me to the right way ?
thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

No, I would not use includes for headers and footers, I would write custom actions so that data could be easily passed to them via attributes.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: call something (set array and get its length ) from include file in jsp
 
Similar Threads
why page not display
Applet Problem
first whack at JSP not working
Errata on HF question?
JRun4