Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to include different jsp pages on different request on a JSP page?  RSS feed

 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

I am having a problem with jsp page.In my web application I have a page that is SearchStudent and it is receiving requests from 5 jsp page(Faculty,HR,Library,Accounts,Placements) all of them will request for search Student.

I want to load each tie different header for each request.

the approach I am thinking is sending a flag with each request(from where it is coming) and based on that include different jsp pages in a div.

Is there any other better approach for this.?

I have made only a single jsp page searchStudent.jsp

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you experiencing problems with your approach?
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not tried it yet.But I am asking is there any better approach to acheive this other than mine?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way not to do it is to try and find out what page you came from via URL. Passing an explicit parameter is a better approach. (Strong versus weak binding.)
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Passing an explicit parameter is a better approach. (Strong versus weak binding.)


will you eleborate it?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A request param, perhaps named command (or whatever else is appropriate), that specifies different values based upon the actions to be taken. This is the HTTP equivalent of passing parameters to a method.

So, along the lines of:

?command=jump-through-hoops
?command=do-somersaults
?command=dance-on-the-head-of-a-pin
?command=whistle-dixie

and so on.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Bear Bibeault

I will try your approach

Thanks
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

One way not to do it is to try and find out what page you came from via URL. Passing an explicit parameter is a better approach. (Strong versus weak binding.)



In my case one JSP is calling to another JSP How can I set parameter.I have Just use something like <c:url="here to go"/> there is noting like request dispatcher or From Subission in my case

So How can I set a parameter when passing request from one JSP page to another JSP page?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Investigate the <jsp:include> and <jsp:param> actions.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By Reading This
https://docs.oracle.com/cd/E19575-01/819-3669/bnajd/index.html


What I understand is I should use JSP:forward with jsp:param and then in second page I should get that JSP;param and based on that I should Include require JSP

Is it right approach?


 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you find yourself trying to forward from one JSP to another JSP, then you're doing something wrong. Your control components should be making decisions like that, not your view components.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So What Approach I should use How can I detect request is coming from which JSP pages?
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First I think you should stop thinking of the HTML which sends requests to your system as "JSP pages". That just leads to a lot of misunderstandings.

And second I think you should stop trying to find out where requests are coming from. If a request should be handled in two (or more) different ways depending on something, then it should include a parameter to help your controller code decide which way to handle it. Probably that parameter should be set as part of the HTML, but based on what you've posted so far there might be many other ways to deal with it.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Spring

So I think this might be good approach pass request to controller and controller will set parameter based on request and that value will be forward to jsp page


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are forwarding from a controller, use scoped variables to convey information.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Bear

I will try your approach Soon will Update my post
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!