how to retreive a & as a value from query string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prisesh26
    New Member
    • Sep 2006
    • 29

    how to retreive a & as a value from query string

    hi,

    iam passing a name "sun & moon" in my query string as a parameter.
    but when i receive it through request.getPara meter iam getting only sun.
    rest are getting ignored due to & symbol.

    how to get the value as wat i entered through query string.
    encoding with another symbol is not adviced. so can any one give a good solution
    please help me
    soon as possible .
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by prisesh26
    hi,

    iam passing a name "sun & moon" in my query string as a parameter.
    but when i receive it through request.getPara meter iam getting only sun.
    rest are getting ignored due to & symbol.

    how to get the value as wat i entered through query string.
    encoding with another symbol is not adviced. so can any one give a good solution
    please help me
    soon as possible .
    Post the code where you are passing the parameter.

    Comment

    • prisesh26
      New Member
      • Sep 2006
      • 29

      #3
      thanks,

      but iam fetching the name in one action class through request.getpara meter and appending with other values with querystring and passing to second action class. when i get in second action class iam not getting the whole string.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by prisesh26
        thanks,

        but iam fetching the name in one action class through request.getpara meter and appending with other values with querystring and passing to second action class. when i get in second action class iam not getting the whole string.
        Read my reply above again.

        Comment

        • prisesh26
          New Member
          • Sep 2006
          • 29

          #5
          sorry,

          iam new to java . i dont no how to pass the code by POST.
          can you help me please.

          from jsp iam doing POST to one class. but from that class i dont no how to post the query string by post when i pass through response.sendre direct.

          to another class

          Comment

          • sukatoa
            Contributor
            • Nov 2007
            • 539

            #6
            Originally posted by prisesh26
            sorry,

            iam new to java . i dont no how to pass the code by POST.
            can you help me please.

            from jsp iam doing POST to one class. but from that class i dont no how to post the query string by post when i pass through response.sendre direct.

            to another class
            Copy the piece of code where you are passing the parameter, paste it here.

            regards,
            sukatoa

            Comment

            • nanaveraa
              New Member
              • May 2008
              • 9

              #7
              Hello frnd
              I think you'll pass the parameter on href. Will you use this type? For example 'http://bytes.com/forum/newreply.php?do =newreply'&'p=3 163121' see the site name. & symbol using middle of the two variable. So you can't retrieve it.
              Use replace statement. For example
              String ss = "str&str1";
              ss = ss.replace('&', 'xxxxx');
              Try this method
              GoodLuck

              Originally posted by prisesh26
              hi,

              iam passing a name "sun & moon" in my query string as a parameter.
              but when i receive it through request.getPara meter iam getting only sun.
              rest are getting ignored due to & symbol.

              how to get the value as wat i entered through query string.
              encoding with another symbol is not adviced. so can any one give a good solution
              please help me
              soon as possible .

              Comment

              • BigDaddyLH
                Recognized Expert Top Contributor
                • Dec 2007
                • 1216

                #8
                Originally posted by nanaveraa
                Hello frnd
                I think you'll pass the parameter on href. Will you use this type? For example 'http://bytes.com/forum/newreply.php?do =newreply'&'p=3 163121' see the site name. & symbol using middle of the two variable. So you can't retrieve it.
                Use replace statement. For example
                String ss = "str&str1";
                ss = ss.replace('&', 'xxxxx');
                Try this method
                GoodLuck
                What if xxxxx is part of the original string? A much better solution is to use the API:

                [CODE=Java]import java.io.Unsuppo rtedEncodingExc eption;
                import java.net.URLEnc oder;
                import java.net.URLDec oder;

                public class URLEncoderTest {
                public static void main(String[] args) throws UnsupportedEnco dingException {
                String charset = "UTF-8";

                String text = "Sturm & Drang = Storm & Stress";
                String encoded = URLEncoder.enco de(text, charset);
                String decoded = URLDecoder.deco de(text, charset);
                System.out.form at("'%s' => '%s' => '%s'%n", text, encoded, decoded);
                }
                }[/CODE]
                Note that this takes care of not just '&', but other special characters as well, like white space and '='.

                Comment

                • raknin
                  New Member
                  • Oct 2007
                  • 82

                  #9
                  I had this problem a few days ago and I solve it as following:

                  Before you send the your request to the server replace all the "&" with some string that you decide about and doesn't appear in the your parameter e.g DUMMY it. on the server just replace the string you relace previously in the client side with the & again. I hope this will help

                  Comment

                  • BigDaddyLH
                    Recognized Expert Top Contributor
                    • Dec 2007
                    • 1216

                    #10
                    Originally posted by raknin
                    I had this problem a few days ago and I solve it as following:

                    Before you send the your request to the server replace all the "&" with some string that you decide about and doesn't appear in the your parameter e.g DUMMY it. on the server just replace the string you relace previously in the client side with the & again. I hope this will help
                    I still think using the HHTP standard and java's standard API, namely URLEncoder/URLDecoder, is the way to go.

                    Comment

                    • prisesh26
                      New Member
                      • Sep 2006
                      • 29

                      #11
                      hi guys,

                      i tried with urlDECODER but its a depricated class so we cannot use that.

                      i tried by replacing the & with %26 and i passed to query string.

                      in request parameter %26 is escaped with & value.

                      so iam getting the value properly

                      now its working fine.
                      thanks dudes.


                      :)

                      Comment

                      • BigDaddyLH
                        Recognized Expert Top Contributor
                        • Dec 2007
                        • 1216

                        #12
                        Originally posted by prisesh26
                        hi guys,

                        i tried with urlDECODER but its a depricated class so we cannot use that.

                        i tried by replacing the & with %26 and i passed to query string.

                        in request parameter %26 is escaped with & value.

                        so iam getting the value properly

                        now its working fine.
                        thanks dudes.


                        :)
                        You are misreading: java.net.URLDec oder is not a deprecated class, at least not as of 1.6:



                        If you take the time to read the API documentation, you'll see that what is deprecated is the version of the decode method that takes one string:
                        [CODE=Java]String decodedText = URLDecoder.deco de(text);//deprecated[/CODE]
                        Like almost all deprecated parts of the API, there are instructions what to do instead. In this, you should use the other version of decode, which takes the name of a charset encoding:
                        [CODE=Java]String decodedText = URLDecoder.deco de(text, "UTF-8");//excellent[/CODE]
                        This is the version I used in my example, above.

                        Hope this clears things up.

                        Comment

                        Working...