aspose file tools*
The moose likes JSP and the fly likes Calling of a PHP file in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Calling of a PHP file in JSP" Watch "Calling of a PHP file in JSP" New topic
Author

Calling of a PHP file in JSP

anand phulwani
Ranch Hand

Joined: Sep 10, 2005
Posts: 242
Dear Ranchers,

I wish to call a PHP file from a JSP,the JSP is base of the portal but have to create some thumbnails from GD library which is supported in PHP so have to call it,have tried Image IO in JSP to create the thumbnails but its working on some snaps and is giving some color exception on others.


Thanks and Regards, Anand
SCJP 5.0 310-055 73%, SCWCD 1.4 310-081 78%, IBM DB2 9 Fundamentals 000-730 62%
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Where is your PHP script?
What is it running under?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
anand phulwani
Ranch Hand

Joined: Sep 10, 2005
Posts: 242
Dear Ben,

The php is script is on the same server and the same folder,
and the JSP is handled by Resin,so think so PHP shud be handled by the same.

Although i was able to accomplish this task,but i have two problems which i want to discuss.but before that let me give you the code of the files.

index.jsp


resize.php


Q 1)This PHP file uses GD library to create thumbnails,and is successful in doing that with any image,but java ImageIO succeed with some and fails with some,why so??,i don't wish to mix JAVA/JSP with any other technology because this shows the weakness/downside of technology/proffessionals

Q 2)I have used a pure java form to call the php page,is there any JSP tag which supports this.I can't use JSTL because the server supports 1.1 and not 2.0.I have tried and but both are not able to service the php file,please infrom about JSTL although i know i won't be able to run it at my server.

Q 3)The data sent to PHP is in a GET form,how to send the same data through POST?
[ April 15, 2007: Message edited by: anand phulwani ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42639
    
  65
i don't wish to mix JAVA/JSP with any other technology because this shows the weakness/downside of technology/proffessionals


That's debatable. It's certainly the mark of a professional that he uses the technologies that allow him to get work done quickly. There are of course other considerations like code complexity and maintainability.

I have used a pure java form to call the php page, is there any JSP tag which supports this. I can't use JSTL because the server supports 1.1 and not 2.0.I have tried.

JSTL has the "import" tag in its core library, which should work here. JSP 1.x containers support JSTL 1.0 (though not JSTL 1.1, I believe). Also see this page: ElOrJstlNotWorkingAsExpected

Instead of using JSTL, you can always write your own tag, which encapsulates the scriptlet you're using now, and which also uses POST if so desired.


Ping & DNS - my free Android networking tools app
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42639
    
  65
What is the problem with ImageIO? Can you post an image that triggers that, and the relevant section of code?
anand phulwani
Ranch Hand

Joined: Sep 10, 2005
Posts: 242
Dear Ulf,

The Code for resizing is

Thumbnail.java


Usage is
java Thumbnail c:\image.jpg c:\thumbnail.jpg 120 80 75


And the image is
Image Link

The exception given is
sun.awt.image.ImageFormatException: Unsupported color conversion request
at sun.awt.image.JPEGImageDecoder.readImage(Native Method)
at sun.awt.image.JPEGImageDecoder.produceImage(Unknown Source)
at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source)
at sun.awt.image.ImageFetcher.fetchloop(Unknown Source)
at sun.awt.image.ImageFetcher.run(Unknown Source)
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

No matter what, this is not the best forum for this.

If your question is about calling PHP scripts from Resin, I can move this to our Forum on the Resin server for you.

If it's about imaging in Java I can move it to our "Other Java APIs".

Let me know which direction you want to choose.

BTW: Have you looked at the JAI?
https://jai-imageio-demos.dev.java.net
I've done some trivial resizing with it and haven't seen any problems with the results.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42639
    
  65
The file download service says "The image �...image.jpg� cannot be displayed, because it contains errors." Maybe there is actually something the matter with that image?

As an aside, why aren't you using ImageIO for writing the file?
[ April 16, 2007: Message edited by: Ulf Dittmer ]
anand phulwani
Ranch Hand

Joined: Sep 10, 2005
Posts: 242
Dear Ulf,

Please Find The updated link as follows

Image Link

Please Use Save Target Asoption over this link,to save it on your computer.

I had a look with ImageIO too,its also giving similar problem.
anand phulwani
Ranch Hand

Joined: Sep 10, 2005
Posts: 242
Dear Ben,

I am sorry for the trouble i caused to you and the team,i am still thinking over it,and would like to know your advice,because the calling is done from JSP so i thought to go for this forum,please advice what do you think about this ,because the question is JSP calling PHP on Resin Server to Create Thumbnails(Imaging Part).
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42639
    
  65
That image uses CMYK as its color model, not RGB. While a perfectly valid JPEG file, Java can not generally deal with those images. It may be possible with ImageIO, but you'd need to delve deep into the ImageReader, ImageReadparam, IOParam and ImageTypeSpecifier classes, and acquire some working knowledge about the CMYK color model. Even then, it may not be possible.

An easier alternative may be the ReadJPEGRaster code shown here. It can read the image, but the colors will be wrong, and each pixel needs to be converted from CMKY to RGB. That's relatively easy to do, though.

Even easier would be to create RGB JPEGs in the first place.
[ April 17, 2007: Message edited by: Ulf Dittmer ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by anand phulwani:
Dear Ben,

I am sorry for the trouble i caused to you and the team,i am still thinking over it,and would like to know your advice,because the calling is done from JSP so i thought to go for this forum,please advice what do you think about this ,because the question is JSP calling PHP on Resin Server to Create Thumbnails(Imaging Part).


You haven't caused anyone any trouble.
I just want to make sure your question ends up in the best forum.

As to whether to use multiple technologies or keep it a pure Java app:
If you're hosting the site and you can get things working quickly and easily by using PHP for the resizing, then as Ulf said earlier, you're making the most efficient use of your time by doing so. If on the other hand this app is going to be packed up and shipped to customers or if maintaining this is going to be troublesome with multiple technologies, then it may be worth the time to get a pure Java solution working.

For the time being, I'll move this to our "Other Java APIs", which our best forum for imaging questions. If you give up on this approach, ask the moderator there to move it to our Resin forum if you have any further questions on integrating PHP and JSP on the same server.

-Ben
 
wood burning stoves
 
subject: Calling of a PHP file in JSP