Professional Web Applications Themes

Servlet -> PHP - PHP Development

I've got a Java Servlet that I want to convert to PHP. My problem is that I have some existing clients which use this servlet at a URL like: [url]http://www.mydomain.com/servlet/MyServlet[/url] I still want the clients to be able to use this URL. I tried using a PHP file called 'MyServlet' and removed the .php extension, but then the server didn't understand that it was a PHP file and sent back plain text. Does anyone know of a solution for this? Can I map the URL to a php file? Thanks, Andrew...

  1. #1

    Default Servlet -> PHP

    I've got a Java Servlet that I want to
    convert to PHP. My problem is that I have
    some existing clients which use this servlet
    at a URL like:

    [url]http://www.mydomain.com/servlet/MyServlet[/url]

    I still want the clients to be able to use this URL.

    I tried using a PHP file called 'MyServlet'
    and removed the .php extension, but then the
    server didn't understand that it was a PHP file
    and sent back plain text.

    Does anyone know of a solution for this?

    Can I map the URL to a php file?

    Thanks,

    Andrew

    Andrew Guest

  2. #2

    Default Re: Servlet -> PHP

    Andrew wrote:
    > I've got a Java Servlet that I want to
    > convert to PHP. My problem is that I have
    > some existing clients which use this servlet
    > at a URL like:
    >
    > [url]http://www.mydomain.com/servlet/MyServlet[/url]
    >
    > I still want the clients to be able to use this URL.
    >
    > I tried using a PHP file called 'MyServlet'
    > and removed the .php extension, but then the
    > server didn't understand that it was a PHP file
    > and sent back plain text.
    >
    > Does anyone know of a solution for this?
    >
    > Can I map the URL to a php file?
    >
    > Thanks,
    >
    > Andrew
    >
    apache's mod_rewrite
    You need to activate it in .htaccess, and add a rule similar to:

    RewriteRule ^servlet/MyServlet$ MyServlet.php [L]


    This will redirect all requests for ./servlet/Myservlet to ./Myservlet.php

    Note: Your isp might have blocked this trick globally. It usually only
    comes with paid-for webspace, or if you co-locate a server.

    Removing the extension is a bad thing (tm) because the webserver doesn't
    know how to handle the file without an extension.
    Milambar Guest

  3. #3

    Default Re: Servlet -> PHP

    > apache's mod_rewrite
    > You need to activate it in .htaccess, and add a rule similar to:
    >
    > RewriteRule ^servlet/MyServlet$ MyServlet.php [L]
    >
    >
    > This will redirect all requests for ./servlet/Myservlet to ./Myservlet.php
    >
    > Note: Your isp might have blocked this trick globally. It usually only
    > comes with paid-for webspace, or if you co-locate a server.
    >
    > Removing the extension is a bad thing (tm) because the webserver doesn't
    > know how to handle the file without an extension.
    Thanks for the info.

    Is mod_rewrite better than using a redirect in .htaccess?

    I just tested a redirect in .htaccess and it seems to work
    but I have a feeling it might be a little slow. (?) I was
    pleasantly surprised to see that the parameters on the end
    of my url (?key=1234) remained intact with the redirect, too.

    Will my parameters get passed with mod_rewrite as well?

    Regards,

    Andrew






    Andrew Guest

  4. #4

    Default Re: Servlet -> PHP

    Andrew wrote:
    >
    >> apache's mod_rewrite
    >> You need to activate it in .htaccess, and add a rule similar to:
    >>
    >> RewriteRule ^servlet/MyServlet$ MyServlet.php [L]
    >>
    >>
    >> This will redirect all requests for ./servlet/Myservlet to
    >> ./Myservlet.php
    >>
    >> Note: Your isp might have blocked this trick globally. It usually only
    >> comes with paid-for webspace, or if you co-locate a server.
    >>
    >> Removing the extension is a bad thing (tm) because the webserver
    >> doesn't know how to handle the file without an extension.
    >
    >
    > Thanks for the info.
    >
    > Is mod_rewrite better than using a redirect in .htaccess?
    >
    > I just tested a redirect in .htaccess and it seems to work
    > but I have a feeling it might be a little slow. (?) I was
    > pleasantly surprised to see that the parameters on the end
    > of my url (?key=1234) remained intact with the redirect, too.
    >
    > Will my parameters get passed with mod_rewrite as well?
    >
    > Regards,
    >
    > Andrew
    Much better, because with mod_rewrite, it shows the old url, ie, the
    address in the url bar will show .../servlet/Myservlet. I think with a
    redirect, the url shows as changed. So your clients will be non-wiser.

    If you have parameters to pass, the rule needs to be a little different,
    can you give an example of the kind of parameters you are attempting to
    pass?
    Milambar Guest

  5. #5

    Default Re: Servlet -> PHP


    > Much better, because with mod_rewrite, it shows the old url, ie, the
    > address in the url bar will show .../servlet/Myservlet. I think with a
    > redirect, the url shows as changed. So your clients will be non-wiser.
    >
    > If you have parameters to pass, the rule needs to be a little different,
    > can you give an example of the kind of parameters you are attempting to
    > pass?
    There are several parameters that need to be passed.

    The full url to the servlet typically looks something like this:

    [url]http://www.mydomain.com/servlet/MyServlet?code=1234&name=andrew&url=www.google.com[/url]

    Andrew


    Andrew Guest

  6. #6

    Default Re: Servlet -> PHP

    Andrew wrote:
    >
    >
    >> Much better, because with mod_rewrite, it shows the old url, ie, the
    >> address in the url bar will show .../servlet/Myservlet. I think with a
    >> redirect, the url shows as changed. So your clients will be non-wiser.
    >>
    >> If you have parameters to pass, the rule needs to be a little
    >> different, can you give an example of the kind of parameters you are
    >> attempting to pass?
    >
    >
    > There are several parameters that need to be passed.
    >
    > The full url to the servlet typically looks something like this:
    >
    > [url]http://www.mydomain.com/servlet/MyServlet?code=1234&name=andrew&url=www.google.com[/url]
    >
    >
    > Andrew
    >
    >
    RewriteRule ^servlet/MyServlet?code=(.*)&name=(.*)&url=(.*)$
    ../Myservlet.php?code=$1&name=$2&url=$3 [L]

    Should work. Emphasis on the word should ;-)

    Its been a while since I needed to use a rewrite with parameters.
    Milambar Guest

  7. #7

    Default Re: Servlet -> PHP

    Milambar wrote:
    >>
    > RewriteRule ^servlet/MyServlet?code=(.*)&name=(.*)&url=(.*)$
    > ./Myservlet.php?code=$1&name=$2&url=$3 [L]
    >
    > Should work. Emphasis on the word should ;-)
    >
    > Its been a while since I needed to use a rewrite with parameters.
    OK, I'll try it a little later and see. :)

    Thanks!

    Andrew


    Andrew Guest

  8. #8

    Default Re: Servlet -> PHP

    By chance, does your php file return results of an sql query? I have a
    servlet that does that, which I would like to replace with a simply php
    file, but not sure how to do it on both the java (client applet) side as
    well as the php (server) side. -Ike

    "Andrew" <andrewnowherenohow.com> wrote in message
    news:mvTkc.2051$Hs1.277newsread2.news.pas.earthli nk.net...
    > I've got a Java Servlet that I want to
    > convert to PHP. My problem is that I have
    > some existing clients which use this servlet
    > at a URL like:
    >
    > [url]http://www.mydomain.com/servlet/MyServlet[/url]
    >
    > I still want the clients to be able to use this URL.
    >
    > I tried using a PHP file called 'MyServlet'
    > and removed the .php extension, but then the
    > server didn't understand that it was a PHP file
    > and sent back plain text.
    >
    > Does anyone know of a solution for this?
    >
    > Can I map the URL to a php file?
    >
    > Thanks,
    >
    > Andrew
    >

    Ike Guest

  9. #9

    Default Re: Servlet -> PHP



    Ike wrote:
    > By chance, does your php file return results of an sql query? I have a
    > servlet that does that, which I would like to replace with a simply php
    > file, but not sure how to do it on both the java (client applet) side as
    > well as the php (server) side. -Ike
    No, it doesn't use any database at this time.

    I'm actually surprised that your applet does.
    Not that many applets use a database that I have seen.

    Andrew


    Andrew Guest

  10. #10

    Default Re: Servlet -> PHP

    I have it calling a servlet which acts as an intermediary to the database
    from/to the applet. I would like to replace the servlet with a mere php page

    "Andrew" <andrewnowherenohow.com> wrote in message
    news:Cf7lc.2712$Hs1.1777newsread2.news.pas.earthl ink.net...
    >
    >
    > Ike wrote:
    >
    > > By chance, does your php file return results of an sql query? I have a
    > > servlet that does that, which I would like to replace with a simply php
    > > file, but not sure how to do it on both the java (client applet) side as
    > > well as the php (server) side. -Ike
    >
    > No, it doesn't use any database at this time.
    >
    > I'm actually surprised that your applet does.
    > Not that many applets use a database that I have seen.
    >
    > Andrew
    >
    >

    Ike Guest

  11. #11

    Default Re: Servlet -> PHP

    Ike wrote:
    > I have it calling a servlet which acts as an intermediary to the database
    > from/to the applet. I would like to replace the servlet with a mere php page
    That doesn't sound very difficult to do.

    I don't know the exact syntax but there are
    probably lots of examples for doing a PHP
    database connection, no?

    It would be almost the same as using a JSP page.

    So far, everything I've tried in PHP has
    been much easier than Java, BTW. I've only
    spent a few hours with PHP, but I am fairly
    proficient at Java.

    Andrew


    Andrew Guest

  12. #12

    Default Re: Servlet -> PHP

    Yeah, I agree with you 100%. In fact, I think for server-side portability,
    php has it all over jsp/servlets.

    "Andrew" <andrewnowherenohow.com> wrote in message
    news:_cclc.3349$V97.1837newsread1.news.pas.earthl ink.net...
    > Ike wrote:
    > > I have it calling a servlet which acts as an intermediary to the
    database
    > > from/to the applet. I would like to replace the servlet with a mere php
    page
    >
    > That doesn't sound very difficult to do.
    >
    > I don't know the exact syntax but there are
    > probably lots of examples for doing a PHP
    > database connection, no?
    >
    > It would be almost the same as using a JSP page.
    >
    > So far, everything I've tried in PHP has
    > been much easier than Java, BTW. I've only
    > spent a few hours with PHP, but I am fairly
    > proficient at Java.
    >
    > Andrew
    >
    >

    Ike Guest

Similar Threads

  1. Java Servlet API - where on Mac OSX?
    By David Mainstreet in forum Coldfusion - Getting Started
    Replies: 1
    Last Post: May 20th, 02:19 PM
  2. Bug in Graph Servlet?
    By prayank in forum Coldfusion - Advanced Techniques
    Replies: 2
    Last Post: March 29th, 10:19 AM
  3. load JPG from SERVLET
    By Nick Zotta in forum Macromedia Flash Data Integration
    Replies: 2
    Last Post: February 17th, 02:40 PM
  4. [PHP-DEV] Servlet SAPI Module
    By Sebastian Bergmann in forum PHP Development
    Replies: 1
    Last Post: September 1st, 06:43 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139