• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Get value in JSP from bean.

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

These are my sample code.

struts.xml


ActionClass.java



Model or Bean.java


index.jsp



doing.jsp


Problem is, I'm not getting that name value in my doing.jsp. What to do?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There could be other problems, but start by not putting any classes in the "java" and "javax" package hierarchies. I'm fairly certain that that will cause problems.

Also note that instead of using a scriptlet like "<%= model.getName() %>" you should use the EL: "${model.name}".
 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

There could be other problems, but start by not putting any classes in the "java" and "javax" package hierarchies. I'm fairly certain that that will cause problems.

I din't get that.

There could be other problems

I think no. Because all code are in-front of you.

there is small change recently done.

doing.jsp


But, no use.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ramakrishna Udupa wrote:
<jsp:useBean id="model" class="java.Model.Model" scope="request"/>



I believe the useBean creates a new instance of Model, effectively replacing the one Struts would use. see here
Why are you using JSP tags instead of Struts 2 tags?
 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Joe Ess

In my recent post, I updated the code doing.jsp. That is correct right? If yes, using that also I'm getting OUT-PUT as.


Displaying nothing.


Thanks:
Ramakrishna K.C
 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Joe Ess


It's not working.


Out-Put is


I'm sure. Its injecting that name value in setters written in Model.java
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ramakrishna Udupa wrote:@Joe Ess

In my recent post, I updated the code doing.jsp. That is correct right?



No. s:bean does the same thing jsp:bean does.
 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


trying all thing. Still Not getting.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ramakrishna Udupa wrote:

There could be other problems, but start by not putting any classes in the "java" and "javax" package hierarchies. I'm fairly certain that that will cause problems.

I din't get that.


In which package are your classes? Now see the first paragraph of the question in https://coderanch.com/t/480744/java-programmer-SCJP/certification/package-starting-java-javax. Do you now see the problem?

There could be other problems

I think no. Because all code are in-front of you.


I said that because I have not gone through all the code. Fixing the issue I mentioned is a necessary condition to fixing the problem, but not necessarily a sufficient one.
 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Ulf Dittmer

Ya.. I got the issue. Thanks for good information. But, After I change the package name, value is not getting display.

Now package becomes com.demo.model.Model

Thanks:
Ramakrishna K.C
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you've made some changes it would be best if you showed us your code again, instead of us guessing what the problem could be.
 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
index.jsp



struts.xml



doing.jsp


Model.java


Action.class


This is my latest code.

Ramakrishna K.C
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not a Struts expert, but I think this still applies:

Joe Ess wrote:I believe the useBean creates a new instance of Model, effectively replacing the one Struts would use. see here

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The issue I believe is that you are loading your data into the Model object which is tied with the ActionClass. After you submit your form, you are then redirecting to another action which does not have access to that ActionClass or its properties anymore.

I see 3 possible options
1) Change your result to . Then will keep the doing.jsp page under the scope of the ActionClass and give you direct access to the Model object
2) Store the "name" attribute in the session, so when you redirect away you can grab the value from the session in your doing.jsp
3) Append the parameter to your result action such as

, then in your doing.jsp you can access the attribute from the request.
 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@ Thanks Raymond Holguin for giving such a good options.


Thanks All.

Ramakrishna K.C
 
reply
    Bookmark Topic Watch Topic
  • New Topic