0

I have a JSP file that @includes two other files.

The first of the included files has a global variable declared within it.

I want to use this variable in the second included file.

It works o.k. and passes compilation but eclipse says that:

*my_var* cannot be resolved to a variable

when looking at the errors under the problems tab.

is there a way to tell eclipse that this variable can be found at the first include? or do something else to stop it from showing this as an error. (preferably in such a way that if I remove the declaration from the first include I will get the error back...)

Andre Holzner
  • 18,333
  • 6
  • 54
  • 63
epeleg
  • 10,347
  • 17
  • 101
  • 151

1 Answers1

2

Eclipse is not good with that, but it doesn't have to - you should not include java code in your JSPs. Instead of java variables, use request attributes and JSTL:

<c:set var="foo" value="bar" />

${foo} <!-- outputs "bar" -->
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • Hi @Bozho, this looks interesting, can you please add more information ? what are the requirements from my java environment to be able to do this? what are request attributes? and what is JSTL? and how does it help me in replacing common code that I want to sare between pages (like a navigation bar for example ? – epeleg Sep 18 '11 at 20:58
  • 1
    Here is a good starting point http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files/3180202#3180202 – Bozho Sep 19 '11 at 06:09