GeeCON Prague 2014*
The moose likes Servlets and the fly likes Using a servlet bean in a jsp file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Using a servlet bean in a jsp file" Watch "Using a servlet bean in a jsp file" New topic
Author

Using a servlet bean in a jsp file

Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
I�m working on upgrading all my code to use Struts Tiles Templates. In the code I define some variables, which have to be used by all my jsp pages. Before my udgrading to Struts Tiles Templates I just included a jsp file, where all the variables was defined - i.e.


But now I have to share the variables in a bean request scope.

The way I will share the variables is by using a servlet bean (Initialize.java), which I call in the way below:

<jsp:useBean id="init" class="ini.Initialize" scope="request" />

My big problem is that now I have to change all my code in the jsp pages to use the variables, by calling the variables using the bean id, called init. I have to change my code from:

<%=ressources.getString("toppanel.choose_language")%>

to

<%=init.resources.getString("toppanel.choose_language")%>

That is a lot of work. Are there any way to get around of this problem?
[ June 27, 2005: Message edited by: Jeppe Fjord ]
Tim Baker
Ranch Hand

Joined: Oct 04, 2003
Posts: 541
Give how similar those two pieces of code are, you can just use the Search / Replace function in your IDE. Most IDE's should support this, I know that Eclipse does.


Kim Jong II (North Korea's Dear Leader) said:Nuclear weapons don't kill people, people kill people.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Using a servlet bean in a jsp file