2

Possible Duplicates:
accessing constants in JSP (without scriptlet)
Reference interface constant from EL

Hi,

I have a public or global variable res used in a protected void function in Admin.java. Can I use this variable in another function login in index.jsp page within the same application. Is it possible?

I have tried using Admin.res in the function in one more class SemanticSearch.java. The value of res is easily retrieved but it is not so in the case if I need to use it in index.jsp. I have tried printed in index.jsp using alert but the value is not printed.

Please help, Regards, Archana

Community
  • 1
  • 1
Archana
  • 237
  • 3
  • 9
  • 17

1 Answers1

1

Here's a tutorial how to do that

Boris Pavlović
  • 63,078
  • 28
  • 122
  • 148
  • The tutorial says to use javabean. But I am not able to understand how to use it for my program. My application has two files index.jsp and admin.java. In admin.java I have a public static variable res. This variable gets its value from another function in SemanticSearch.java. The value is populated in SemanticSearch.java and is send back to admin.java file (i.e. to a function). From here the value of res has to be passed to index.jsp. Please note the function in admin.java from which the variable res has to be passed is a void function and therefore cannot have (statement) return res. – Archana Feb 15 '11 at 07:09
  • I have checked the other related questions and in their answers I have understood I can use request.setAttribute and get....methods. I have tried using them as in: – Archana Feb 15 '11 at 10:29
  • public static String rest; declared in Admin.java file.Then in the -----protected void doGet method in Admin.java I have written: String res=semsearch.searchForUser(userName, password); System.out.println("The value of res been passed is "+res); request.setAttribute("rest", res);--------------------------/ when I try to print the value of rest here the value is null. The value in variable res is C Language which I have got from the function written in SemanticSearch.java file. Why do I get a null value here? Once this is acheived I need to get this value to be passed to index.jsp. Please help. – Archana Feb 15 '11 at 10:34