This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Is there any possibility of declaring variable ?  RSS feed

 
mallikarjun dontamsetti
Ranch Hand
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Is there any possibility of declaring a variable in jsp (Not asking any scripting variables). Is "property" in <jsp:getProperty> tag is a variable?
Thanks in advance..
 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, there are many possibilities to do such a thing. The question is, why do you want to do that?
 
mallikarjun dontamsetti
Ranch Hand
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dieter Quickfend wrote:Sure, there are many possibilities to do such a thing. The question is, why do you want to do that?

Thanks for reply i am learning jsp thinking about it. So could You please give me some examples or links to find it
 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One possibility:

<%! int a; %>

but be advised that this is not a good idea, and considered very bad practice nowadays. In general, you don't declare things in JSP, you just show values and take values from the user, and everything else is done somewhere else. JSP only represents the view. But if you keep learning JSP, you'll definitely learn more about that soon!

You should declare a local variable in a servlet, initialize is to the value you want it to have and store it in the scope you want it in, that's the right way.
 
mallikarjun dontamsetti
Ranch Hand
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mallikarjun don wrote:
(Not asking any scripting variables).

As i mention but thanks for reply
 
puneeth poduri
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
depends ..
you can use the <jsp:usebean> to get a bean and use the <jsp:getproperty> on that bean .
hope it has helped you.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In modern JSP, with no scriptlets, you don't create local variables at all. Rather you create scoped variables in one of the four scopes: page, request, session or application. Generally, such scoped variables are set up by the controller for the page, and merely consumed by the JSP. If you are trying to do a lot of processing in the JSP, rather than doing it in the controller, you are not thinking in the correct terms for modern web applications.

Perhaps this article could be of help in learning proper web application structure for modern web apps.
 
mallikarjun dontamsetti
Ranch Hand
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK thanks i will fallow the mvc architecture .But what about the "property"(jsp:getProperty) is that a variable? I know it reference to the bean class variable can i call the property as a variable?

And is there any Naming convention for scoped variables.If i use JSTL is there any naming convention for variables

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, a property is not a variable. It is a property of a bean.

Naming of scoped variables is conventionally the same as for Java variables.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!