Two JSP Tags in 1 HTML page

Posted on 2006-11-02
Last Modified: 2010-04-01

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?
Question by:CSecurity
LVL 92

Expert Comment

ID: 17857002
have u tried

<%= a %>

Accepted Solution

KnightFire earned 500 total points
ID: 17857486
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.
LVL 17

Author Comment

ID: 17857801
Again I got error in this line:

 out.print( titles[0] );

But I defined them at TOP of opening of <% JSP tag
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.


Expert Comment

ID: 17857918
can you paste your JSP page?
LVL 10

Expert Comment

ID: 17858336
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

LVL 17

Author Comment

ID: 17860265
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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
difference between member and local variables. 29 133
bean mapper frameworks 5 60
withoutString  challenge 40 197
jsp login check 12 28
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now