In my application I am working on I have a JSP called manageissues that will display, you guessed it, issues. Depending on what query strings I pass in from other pages will determine the initial view of the issues. It could one or more of the following:
1 of 3 different issue levels
a Date range of issues
So I mignt have a link that looks something like:
And that's not even all of them. I have a servlet that gets called that actually gets all the data I need and forwards this data in the request to the manageissues page.
What I am wondering is, what is the best way to handle all the different possible combinations of query strings I might have? Should I use more than one servlet? Should I be doing this a totally different way alltogether? Any hints, tips, suggestions would be helpful.
Let's pretend I am not using struts, because I'm not. And I won't.
Joined: Jul 11, 2002
gregg, whether You use struts or not, you may be better of using some sort of MVC. Struts is just an implementation of the good old and well appreciated MVC pattern. Anyway, the struts classes help you a bit, now you have to write it yourself. What I mean is the following. Your code of what the user wants is in html and is transferred in the request when submitting the html form. (sorry if I make it too easy to understand) Then struts classes can automatically put all the request variables in a bean (a simple pojo, with getters and setters) If you are not using struts then you have to write that yourself. After having the variables in a simple java object, your servlet has to do something with the variables. But servlets are not designed to do all the work. You have to create an object that in its constructor receives the javabean, (or a static method might do as well, but that depends on design) and that object creates the querystring for you depending on the variables in the javabean. That is send back to the servlet and presto. Hope that answers your question. Anyway make sure the servlet does not do too much work itself. Let helper classes do all the hard work.
swimming certificate (A & B), shoelaces diploma, and some useless java ones.
I think I am being misunderstood. I don't have a form. I am creating links, some static, some dynamic. These links are links to my manageissues servlet and they have query strings attached to them. So when my servlet gets called, I do some work based on those query strings and then I forward to my JSP.
I am wondering, with the amount of query strings and the many possible combinations I have, what is the best approach to this. [ September 30, 2004: Message edited by: Gregg Bolinger ]
Joined: Jul 11, 2002
hi gregg, another thing you could do on your jsp is look at custom tags. Depending on which variables are passed in show the correct view. This takes out all the clutter in the jsp page. cheers
Originally posted by Bear Bibeault: True or false:
1)The JSP page will list a collection of issues. 2)The request params are used to filter which issues get shown.
If both answers are true, your servlet shoud handle all the filtering and just deliver a list of issues to the JSP which could care less how the list of issues was obtained.
Especially if using JSTL and EL, your JSP page will factor down into a small, concise page.
True and true and that is my goal. What I guess I am really asking and not conveying property is what is the best way to handle all the different query string options in the servlet? A bunch of if/else's? Should I specify different servlet for different filters?
When I've done something similar, I abstracted the query into a series of model classes (all implementing a common interface) that the single servlet would use based upon the settings of the filters. Bascially, I pushed the details as far "down" into the hiearchy as I could so that the JSP and the servlet did as little work as possible.
Originally posted by Bear Bibeault: When I've done something similar, I abstracted the query into a series of model classes (all implementing a common interface) that the single servlet would use based upon the settings of the filters. Bascially, I pushed the details as far "down" into the hiearchy as I could so that the JSP and the servlet did as little work as possible.
That's a solid approach. I'll play around with that and see where it takes me. Thanks.