• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

this don't make sense jsp variable declaration

 
Ray Smilgius
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my.jsp code below
the problem is if I pass the smyDir into the test() method it works. I don't understand if it is global why is it undefined inside my function.
<%@ page language="java" %>
<% String smyDir = request.getRequestURI().substring(0,(request.getRequestURI().indexOf("/",1))); %>
<%!
public void test(int iWidth, JspWriter out)
{
try{
out.print("<img src=\"" + smyDir + "/images/rans.gif\" width=\"\"" + iWidth + " height=\"1\">");
}catch(IOException e14)
{
System.out.println("IOException at Spacer");
}

}
%>
thanks Ray
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its not global (or more correctly instance variable) .
when u defne somthn between the <%! %> it is an instance variable (like the function u defined).
anything between the <% %> is actually being done inside the service method of the jsp servlet!
 
Ray Smilgius
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you this makes alot more sense.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic