• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

Struts 2: using Struts 1 form bean

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am currently trying to convert my application from Struts 1 to Struts 2. And so, for reducing the amount of work required, I am trying to keep the existing JSP's as it is and trying to make some minimul changes.

I had the below in my JSP:

<jsp:useBean id="user" class="user.UserData" scope="request"/>
<jsp:setProperty name="user" property="*"/>


However, after submitting the above form, in my action class, I wasn't been able to retrieve the above bean object from the request object. I am doing the following to retrieve the above bean object in my struts 2 action class:

HttpServletRequest request = ServletActionContext.getRequest() ;
UserData obj = (UserData)request.getAttrribute("user");


In the above code, obj is always null and I wasn't been able to retrieve the data that was set in the html form.

Is there anything, I am missing ?





 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you using JSP tags instead of Struts tags? Technically you aren't using Struts if you are using JSP tags and directly accessing the request object.
The way I understand the useBean scope, if the scope is "request" you can only use the bean during the request that renders the JSP. You cannot use it on the request from that JSP page. See here.
My advice would be:
1. Learn to use Struts 2 correctly. It is much easier and more productive to use compared to plain JSP's or Struts 1. If you mix all 3 technologies in the same application you are asking for development and maintenance problems.
2. Read the Struts 2 Migration Guide (scroll down to "Struts 1 to Struts 2"). There are tools and best practices to help you out in migrating.
 
Rahul Chaitanya
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much for the information. We actually had a lots of pages to be modified to Struts 2 and so, for reducing the amount of work load, management suggested to keep, most of the exiting JSP's as it is and make minor changes and so, the application will be moved to Struts 2.

JSP:UseBean is what basically bean present in the older JSP and so, I am trying to retrieve that object in the Struts 2 action class, however, from your message, it seems like it doesn't possible. Is there a way, that I can retrieve that bean in Struts 2 action class without using Struts 2 tag for that bean ? I know, if I change the scope to session, it will work but earlier that was set to request scope and so, wondering abotu the impacts.

So the objective is to copy that bean into similar object in Struts 2 actin class and so, can I do something like below:

<jsp:useBean id="user" class="user.UserData" scope="request"/>
<jsp:setProperty name="user" property="*"/>
<s:set name="action class object name" value="user" />

Even in the above approach, my action class object is not being set ? Any suggestiosn ?

 
He's my best friend. Not yours. Mine. You can have this tiny ad:
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic