Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to formard a JSP to other JSP

 
yulina shu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have problem to forward a jsp page to other jsp which is with different Action and ActionForm.

e.g.
in search.jsp, when click "Search" button, it goes to display SearchResult page, which combines with SearchResultForm and SearchResultAction.


Thanks and regards,
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a little unclear about what you are attemting to do, and what is going wrong, but one thing you should understand is that when you submit a form from a JSP, the action attribute of the <form> tag should be a struts action, not a JSP. Once the action has performed its functions, it should then forward to a JSP.
 
yulina shu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Merrill,

Thanks so much for your reply.

I tried to forward to searchresult.jsp in searchAction, but it did not go to searchresult page instead of back to the same page. I used a button with onClick event, is this a problem?

I am sorry I can not remember my code, it is not in my hand now.

Thanks again.
 
Tim Manchester
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you need are 10 things:
1. Your originating jsp (search.jsp)
2. Your jsp needs to know which action you're going to use (the following is an example of what the form tag in your jsp might look like):
<html:form action="/search">
3. The form for that jsp (searchForm.java)
4. The action for that jsp (SearchAction.java)
5. The jsp to forward to (searchResults.jsp)
6. Your jsp needs to know which action you're going to use (the following is an example of what the form tag in your jsp might look like):
<html:form action="/searchResults">
7. The form for that jsp (searchResultsForm.java)
8. The action for that jsp (searchResultsAction.java)
9. Both jsps need to be listed in your web.xml file
10. Your forms need to be listed in your struts-config.xml file (note, the following is an example, it is probably not exactly right for your use):
<form-beans>
<form-bean name="searchForm" type="searchForm"></form-bean>
<form-bean name="searchResultsForm" type="searchResultsForm"></form-bean>
</form-beans>
9. Lastly your actions and forwards need to be listed in your struts-config.xml file (again, the following example is probably not exactly right for you, it's just an example):
<action-mappings>
<action name="searchForm" path="/search" type="searchAction">
<forward name="searchResults" path="/searchResults"></forward>
</action>
</action-mappings>

It's not enough to have all the jsps and java classes in place. You need to tell the web server about the pages in the web.xml file and you need to tell struts what all the jsp/form/action/forward relationships are in sturts-config.xml.

It can be a bit much to digest, but after you do it a couple of times you'll get it.

Regards,

- DM_Tim

[ March 21, 2005: Message edited by: Tim Manchester ]
[ March 21, 2005: Message edited by: Tim Manchester ]
 
yulina shu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Tim. I did define those forward-mapping and form-beans, and tried to forward to searchResult form searchAction, but it goes to the same search page instead of going to searchResult page. I don't know what it is wrong. Maybe I did not define form-bean correctly.

I will try to do it again following your steps and see what I can get.

Thanks,
 
Tim Manchester
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, that's not it. You are forwarded by struts based on the forward in your action mapping (or global forward). Double check to make sure that the forward in your struts-config.xml is correct AND make sure that the page you want to foward to is mapped to the name you think it is in your web.xml file AND make sure your searchAction is picking the right forward in the execute method.

If you have all that lined up. You'll get to the right place.

- DM_Tim
 
yulina shu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Tim.
 
yulina shu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I can go to searchResult page from search page now, but it did not excute the searchResultAction class before loading the result page.

Please point out where I made a mistake, thanks!

(1) defined the form

<form-bean name="ParticipantSearchForm"
type="com.caspar.advanceSearch.form.ParticipantSearchForm" />

(2) defined the action-mapping
<action path="/searchResultSumit"
type="com.caspar.advanceSearch.action.ParticipantSearchAction"
name="ParticipantSearchForm"
scope="request"
input="/pages/searchResult.jsp" >
<forward
name="success"
path="/pages/searchResult.jsp"/>
</action>

(3)in searchResult page, I have
<html:form action="/searchResultSumit" >

Thanks for help!
 
Tim Manchester
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What makes you think you didn't go into your SearchResultsAction.execute method ? Something had to tell struts where to go from your SearchResults page (the forward in your action class). Put a System.out statement in the execute method (and a breakpoint if you can) just to be sure you really aren't getting there. I suspect you are.

Regards,

- DM_Tim
 
yulina shu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim, I used debug and set a breakpoint in ParticipantSearchAction class, it never goes there. But it did go to ParticipantSearchForm.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic