Hi I am new to this site. My doubt is regarding the controlling and the general flow. Its necessary to have just one servlet controller that takes the request parameters from one jsp and delegate it to some other jsp.But when there are thousands of jsp's and there is only one controller then how does the servlet controller knows from which jsp the request is comming and which page to render next. Where exactly the mapping takes place? I think its a very fundamental question but I am unable to get the answer.? Please get back to me.
First you should think whether you need to use a single Servlet as a controller for many JSP pages. May be a subclass of the controller should handle that? Or you should look into the possibility of using an MVC framework like Struts or JSF.
If you really want to use a single controller for multiple JSP pages creating hardcoded dependencies, you can find the referring page by: String myReferer = request.getHeader("referer");
Later you can use the myReferer to chain the response URL. Hope this helps.
Note: Your name does not seem to be following the naming policy. JavaRanch has a naming policy, which is strictly enforced. Please read the policy and change your display name if you wish to continue posting here.
You can change your name: here [ March 01, 2005: Message edited by: Hari Gangadharan ]
<B>Hari Gangadharan</B><BR>Unix is user friendly..<BR>but it chooses to whom it is friendly with!
No its not necessary to have only one controller to control the entire app.
Moreover, some reading required on FrontController Pattern. Hope you will get the answer. I am posting a brief description on FrontController from IBM DeveloperWorks. Here it goes,
"Front Controller is a controlling component that holds the common processing logic that occurs within the presentation tier. It handles client requests and manages security, state management, error handling, and navigation. The Front Controller centralizes control logic that might otherwise be duplicated, and dispatches the requests to appropriate worker components.
As a component that provides the initial single point of entry for all client requests, it is also known as Front Component. Multiple Front Controllers can be designed for different business use cases, which together manage the workflow of a Web application." [ March 01, 2005: Message edited by: Adeel Ansari ]
You can have a properties file configured, which is read and interpretted by the controller to choose which jsp page to redirect to, based on the current request. [ March 01, 2005: Message edited by: kolkata prince ]
Work like you don't need the money. Love like you've never been hated. Dance like nobody's watching. Sing like nobody's listening. Live like it's Heaven on Earth.
Currently I Reside HereWEBlog
Durga Prasanna Kar
Joined: Feb 28, 2005
Its fine that I should use MVC pattern but I want to know where these mapping exactly happens.If at a time two jsp's with varying parameter's are requested at the same time then how the servlet controller will map jsp's to thier appropriate response pages.
Joined: Aug 15, 2004
A servlet container manages multiple request simultaneously. You need not worry about. Mapping could be done using Map, Property file, xml file.
Assume that each jsp page you assign a page id in a properties/xml file.
In the Controller you can have the properties file parsed and loaded into memory (In the Init).
Please not that this is just a suggestion, not an exact implementaion. [ March 02, 2005: Message edited by: Senthil B Kumar ]
Joined: Aug 15, 2004
Originally posted by kri shan: Mapping could be done using Struts-config.xml file in Struts. So you need not wory about mapping, if you use Struts like frameworks.
Its not a struts specific question.
We should not talk about struts here because it might be the new/not known term for her and would increase her headache.
Senthil B Kumar
Joined: Feb 09, 2004
Or we can take it in the sense that a New Term/Techonology is being introduced
Either we go for Re-Inventing the wheel, since we need our wheel to be a Square or Adjust with an Existing wheel invented by someone [ March 02, 2005: Message edited by: Senthil B Kumar ]
Joined: Aug 15, 2004
Originally posted by Senthil B Kumar: Or we can take it in the sense that a New Term/Techonology is being introduced
Either we go for Re-Inventing the wheel, since we need our wheel to be a Square or Adjust with an Existing wheel invented by someone
Whatever. Although struts is a popular framework, but I am not in favor of struts. For more search jsp forum this has been discussed sometimes back. Struts got the remarks like, overly complex, bloated, not nicely implemented. . Moreover, struts is out-dated for newbies, but its me.
The one should know the whole mechanism, core concept and theory in order to learn the real stuff. Thus I am not in favor of using any of ready-made frameworks while you want to learn some design pattern or architecture, unless you have no other choice around.
Anyhow, more discussion on this would go off topic. [ March 02, 2005: Message edited by: Adeel Ansari ]
Hello Durga, this is a good question because it is fundamental.
> My doubt is regarding the controlling and the general flow. > Its necessary to have just one servlet controller that takes the request > parameters from one jsp and delegate it to some other jsp.
Controller concept is to handle the user's Interactions with the page. Form submission, query/ edit and navigation, as well as simply requesting pages.
Different areas of data (News, Searches, Edit forms, Static Content) would have different Controllers requirements. Implementation could be under any name or place but you what a class is for.
> But when there are thousands of jsp's and there is only one controller
I would refer you to the Spring framework which uses meaningful names for meaningful concepts. 'Handler' or 'Interceptor' may be used as early stage of request handling to handle generic Login, Menus, templating etc before delegating to the Controller which handles the user's major task.
If there are thousands of jsps then they are 1000x similar templated content and similar behaviour. Or there are multiple Controllers.
> then how does the servlet controller knows from which jsp the request is > comming and which page to render next.
Let's take a sidestep: Meaningful designs might have StaticPageController, [customer data] SearchController, [customer data] EditController, ForumPageController, IntroPageController, ...
Here's a tricky one, for knowing where you are on the Web: what about the URL path?
As for coming or going, that's also a good question. The answer is fundamental: it depends on whether you need to do anything or not. If your apoplication is passive, let HTML do the navigation for you; you controller only has to return the right static content.
If your application has to take some action, then the controller has to handle this and flow or redirect onwards. You guessed it, form submissions and interaction.
So if you structure your data areas to be requested into paths, eg /cust/search, /cust/edit, /order/search etc, and implement Controller functionality sensibly for these, you'll probably have a good idea of where you are and what you're doing...
as well as a fairly sensible software design.
As to exactly which customer, search criteria, selection etc you are working with -- nobody's found a better use for URL parameters. For each page when you generate action and navigation hotlinks in the JSP you output the data to parameterize the request.
Lastly, paths are useful for document areas. The machine uses paths in the file system so /docs/* might go to DocumentController which sources content from eg. the file system.
Anyway, check out the Spring framework. I recommend Tomcat/ Spring/ JDO as an effective combination. You want to understand clean and direct application code to get the job done. Hope this helps,