Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get value in JSP from bean.

 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • 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?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Joe Ess
Bartender
Posts: 9319
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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: 9319
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator


trying all thing. Still Not getting.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • 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 http://www.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
  • 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: 9319
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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: 42968
73
  • Mark post as helpful
  • send pies
  • 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
 
Raymond Holguin
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
@ Thanks Raymond Holguin for giving such a good options.


Thanks All.

Ramakrishna K.C
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic