Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

how to assign value to java bean using <jsp:setProperty> in jsp?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello! I want to assign value dynamically to javabean through "<jsp:setProperty>" tag. i want to asign value like this
.
but it give me error. "request.getParameter("user-name)" return a value from previous form. please tell me how can i initiate my bean dynamically. thanks
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try using quotes(" ") on value parameter.

<jsp:useBean id="b" class="com.fyp.MyBean" scope="session" />
<jsp:setProperty name="b" property="password" value= "<%= request.getParameter("user-name")" />


Thanks
Anchit
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

and still you can improve as in



but Again, instatiation and set values should be done on Servlet . what you have to do in jsp is just *get* values.
 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Seetharaman Venkatasamy wrote:


Shouldn't that be ${param['user-name']}? Because ${param.user-name} would resolve into the value of an attribute name being subtracted from a parameter called user.
 
Marshal
Posts: 67425
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed. It's a poor idea to use parameter names that do not conform to Java identifier rules for this reason.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are absolutely Correct Rob.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any reason why



would not work?

If you're going to use this tag, then I would suggest using it to its full potential.

If you're going to use EL, I would recommend the <c:set> tag instead of <jsp:setProperty>

ie
 
Bear Bibeault
Marshal
Posts: 67425
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the setProperty action, while still in JSP is a JSP1 dinosaur that should be replaced with JSTL.
    Bookmark Topic Watch Topic
  • New Topic