File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Get value in JSP from bean. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Get value in JSP from bean." Watch "Get value in JSP from bean." New topic
Author

Get value in JSP from bean.

Ramakrishna Udupa
Ranch Hand

Joined: Aug 09, 2013
Posts: 253
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
Marshal

Joined: Mar 22, 2005
Posts: 42931
    
  68
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

Joined: Aug 09, 2013
Posts: 253
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

Joined: Oct 29, 2001
Posts: 8997
    
    9

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?


[How To Ask Questions On JavaRanch]
Ramakrishna Udupa
Ranch Hand

Joined: Aug 09, 2013
Posts: 253
@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

Joined: Aug 09, 2013
Posts: 253
@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

Joined: Oct 29, 2001
Posts: 8997
    
    9

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

Joined: Aug 09, 2013
Posts: 253


trying all thing. Still Not getting.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42931
    
  68
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

Joined: Aug 09, 2013
Posts: 253
@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

Joined: Oct 29, 2001
Posts: 8997
    
    9

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

Joined: Aug 09, 2013
Posts: 253
index.jsp



struts.xml



doing.jsp


Model.java


Action.class


This is my latest code.

Ramakrishna K.C
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42931
    
  68
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

Joined: Aug 11, 2009
Posts: 81
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

Joined: Aug 09, 2013
Posts: 253
@ Thanks Raymond Holguin for giving such a good options.


Thanks All.

Ramakrishna K.C
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get value in JSP from bean.