10 Replies Latest reply: Dec 12, 2008 11:57 AM by 796440 RSS

    URL parsing

    807589
      Hello Friends,

      I have couple of JSP pages. The URL for each of the Jsp page shown in browser looks somelike as follows.

      http://order.xyz.com/?p_mycode=2Mon_Fr&mnid=in_ss_ppo_hino_soos

      What I want ti achieve is as follows:--

      In my Jsp page, I should be able to grab above URL and then be able to parse the URL for parameternames and parametervalues and put it in Hashmap (cause i want to send these bunch of parameters to next pages VIA session)

      So for example above URL after parsing will give me a Hashmap containing URL parameters as follows :--
      p_mycode ------- 2Mon_Fr
      mnid ---------- in_ss_ppo_hino_soos

      Can any one help me here. have done similar thing before ?

      a>How to grab the URL in the Jsp page ?
      b>How to parse URL to get name  ---   value parameters in the Haspmap (number of URL parameters are dynamically changing. Meaning one Jsp page may have 2 parameters other page may have 7 parameters)
      c>How to pass the haspmap in session ?

      Code snippet will help !


      thanks,
      pp
        • 1. Re: URL parsing
          DrClap
          When you say "in my JSP page" does that mean you want the JSP code in that page to do something when it's executed? Or did you have in mind the output of the JSP which is in the browser? Or did you want something else to look in the source code of the JSP?

          And when you said "grab" a URL, exactly where is that URL coming from? (Follow-up questions to that depend on the answers to the previous questions.)

          Edit: my best guess is that the URL in question is the one that requests the JSP. In that case you haven't read any tutorials or other educational material about JSP and you don't understand that you're just asking for the request parameters, which your server has already put into a Map for you. But surely that can't be right.
          • 2. Re: URL parsing
            796440
            Please don't crosspost.

            [http://forums.sun.com/thread.jspa?threadID=5354947]
            • 3. Re: URL parsing
              807589
              Thanks DrClap.

              I want Jsp code to execute in each of the JSP page that will do following :---


              a> The Jsp code snippet ( <% .............. %>) will grab the URL appearing in the browser's URL

              b> The snippet will then parse the URL to get name --- value parameters from the URL (number of parameter may be 2 or 10. depends)

              c>Then same snippet will then prepare some collection (i guess HaspMap) and put all those bunch of parameternames and values in the collection.

              d>Then same snippet will PUT that collection in the session ---- ready tobe passed to next page as session object.

              Hope this helps.

              thanks,
              pp
              • 4. Re: URL parsing
                DrClap
                (sigh) Just get the request parameters. You don't have to parse anything. And do have a look at some basic examples of how that's done. You should find them in chapter 1 or 2 of your book.
                • 5. Re: URL parsing
                  807589
                  Hello DrClap,

                  The way you suggested assumes that you already know the parametersnames (xyz) coming in the URL. and then you would use getParameter("xyz") to get that parameter value. thats easy.

                  My problem is more than that. The parametersnames we would be getting in our URLs are UNKNOWN. they keep changing. they are not known in advance. so i do not know.

                  so only way left for me is to get the whole URL string and then parse it using the delimiters ( & ) and then tokenizer.

                  Has any one done this kind ?

                  thanks again.
                  pp
                  • 6. Re: URL parsing
                    807589
                    Take a look at the API for ServletRequest.

                    It's a good idea to bookmark the API: [http://java.sun.com/javaee/5/docs/api/]
                    • 7. Re: URL parsing
                      796447
                      Edit: Nevermind, I might post back in a bit...
                      • 8. Re: URL parsing
                        796277
                        I wonder what request.getParameterMap() does?
                        • 9. Re: URL parsing
                          807589
                          TexMark wrote:
                          I wonder what request.getParameterMap() does?
                          This getParameterMap ()?
                          • 10. Re: URL parsing
                            807589
                            Thanks all.

                            getParameterMap can do the trick.

                            I will try and let u know.

                            thanks again
                            pp