• Post Reply Bookmark Topic Watch Topic
  • New Topic

Lots of Query Strings: Best Approach  RSS feed

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

  • my issues
  • everyone's issues
  • 1 of 3 different issue levels
  • today's issues
  • a Date range of issues


  • So I mignt have a link that looks something like:

    manageissues?level=2&view=mine&range=bla

    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.

    Thanks.
     
    Mark Spritzler
    ranger
    Sheriff
    Posts: 17309
    11
    IntelliJ IDE Mac Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    One word, Struts.

    That way you can have forwardmappings to forward them. or gettign the "parameters" from the form.

    I know that Struts can help, my brain is just not in Struts mode right now. I am currently writing JUnit tests, so my mind is elsewhere.

    Mark
     
    Gregg Bolinger
    Ranch Hand
    Posts: 15304
    6
    Chrome IntelliJ IDE Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Let's pretend I am not using struts, because I'm not. And I won't.
     
    friso dejonge
    Ranch Hand
    Posts: 162
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.

    regards,
    friso
     
    Gregg Bolinger
    Ranch Hand
    Posts: 15304
    6
    Chrome IntelliJ IDE Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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 ]
     
    friso dejonge
    Ranch Hand
    Posts: 162
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 65833
    134
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    Gregg Bolinger
    Ranch Hand
    Posts: 15304
    6
    Chrome IntelliJ IDE Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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?
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 65833
    134
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    Gregg Bolinger
    Ranch Hand
    Posts: 15304
    6
    Chrome IntelliJ IDE Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    Adeel Ansari
    Ranch Hand
    Posts: 2874
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Sounds like command pattern.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!