• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

Two JSP Tags in 1 HTML page

Hello!

I have a JSP page and I open <% jsp tag in it. Then I close it with %>

In first tag I define a variable: int a = 23;

Then I put a lot of HTML code... Now I want to print 'a' variable in middle of html. So I re-open <% JSP tag.

But it says 'a' is not defined!

What should I do?
0
CSecurity
Asked:
CSecurity
1 Solution
 
objectsCommented:
have u tried

<%= a %>
0
 
KnightFireCommented:
Scope in JSPs is the same as java, if you get really stuck then examine the generated servlet that is created from the JSP.

objects comment is correct as <%= a %> should print the value of a. If it doens't then a must have gone out of scope, meaning you probably defined it within a loop or similar in the first set of JSP tags. Make sure that a is defined outside any loops or other constructs within the tags.
0
 
CSecurityAuthor Commented:
Again I got error in this line:

 out.print( titles[0] );

But I defined them at TOP of opening of <% JSP tag
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
KnightFireCommented:
can you paste your JSP page?
0
 
jaggernatCommented:
Make sure for every opening <% , there is a closing %>
Make sure all html tags are closed properly.

<html tags>

<%

All your java code

%>

<html tags>

<%

All your java code

%>
..
0
 
CSecurityAuthor Commented:
The problem was that I should define them at TOP of code... it was in try and catch! ALTOUGHT everytime it goes to try and never goes to catch (no error occurs) but it should define before everything!

Thanks all
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now