• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
paramsHead.length will return the array's length
 
Sheriff
Posts: 67748
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
ben josh
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what do you mean by the hard why ?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The easy way : paramsHead.length
 
Bear Bibeault
Sheriff
Posts: 67748
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
ben josh
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67748
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you serious? You obviously can't reference a variable that was never created.
 
ben josh
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
ben josh
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
ben josh
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67748
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic