Results 1 to 10 of 10

Thread: Php to jsp

  1. #1
    algo_avaj is offline Member
    Join Date
    Jul 2013
    Posts
    9
    Rep Power
    0

    Default Php to jsp

    Hi Guys,

    Does anyone of you know to convert this code into JSP?

    PHP Code:
     function getAll_details()
        {
           foreach ($_SERVER as $name => $value)
           {
               if (substr($name, 0, 5) == 'HTTP_')
               {
                   $hdr[str_replace(' ', '-', strtoupper(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
               }
           }
           return $hdr;
        }

    Hoping for your quick response.

    Thanks

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,004
    Rep Power
    6

    Default Re: Php to jsp

    "translate" is the name of the game. When people start to talk about conversions I get a rash all over.

    And you can't translate that 1:1, for one you wouldn't have that _SERVER array available to you in a Java web environment. In stead of trying to translate the code without having to think about it, try to figure out what this PHP thing functionally does. Then try to implement that same functionality in a servlet.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    algo_avaj is offline Member
    Join Date
    Jul 2013
    Posts
    9
    Rep Power
    0

    Default Re: Php to jsp

    Hi Erik,

    Thanks for your advice. may i know the right equivalent of $_SERVER to JSP?

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,004
    Rep Power
    6

    Default Re: Php to jsp

    I just told you that there isn't such a thing.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    946
    Rep Power
    2

    Default Re: Php to jsp

    Find out what this code does. Apparently it loops over all HTTP headers, and does some weird stuff with the values and toUpperCase, then toLowerCase and replacing _ with -.... It adds the result in a named array (read: HashMap) and returns it. HttpServletRequest (Java EE 5 SDK) is your friend here.

  6. #6
    algo_avaj is offline Member
    Join Date
    Jul 2013
    Posts
    9
    Rep Power
    0

    Default Re: Php to jsp

    i think this one is the equivalent (request.getHeaderNames()). I realized the code above is equivalent to this link
    [Moderator edit: link removed]Request Headers in JSP

    By the way, thanks again. I post the url for future references.
    Last edited by DarrylBurke; 07-30-2013 at 12:28 PM.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default Re: Php to jsp

    I've removed the link as that site is infamous for bad examples and worse code.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  8. #8
    algo_avaj is offline Member
    Join Date
    Jul 2013
    Posts
    9
    Rep Power
    0

    Default Re: Php to jsp

    Quote Originally Posted by DarrylBurke View Post
    I've removed the link as that site is infamous for bad examples and worse code.

    db
    Oh, sorry for this.

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default Re: Php to jsp

    Quote Originally Posted by algo_avaj View Post
    Oh, sorry for this.
    No need to apologize; you didn't know that or you wouldn't have posted that link. But I do advise that you stay away from that site, for your own sake.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  10. #10
    algo_avaj is offline Member
    Join Date
    Jul 2013
    Posts
    9
    Rep Power
    0

    Default Re: Php to jsp

    Quote Originally Posted by SurfMan View Post
    Find out what this code does. Apparently it loops over all HTTP headers, and does some weird stuff with the values and toUpperCase, then toLowerCase and replacing _ with -.... It adds the result in a named array (read: HashMap) and returns it. HttpServletRequest (Java EE 5 SDK) is your friend here.
    Thanks to this, great help.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •