Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling of a PHP file in JSP

 
anand phulwani
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is your PHP script?
What is it running under?
 
anand phulwani
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the problem with ImageIO? Can you post an image that triggers that, and the relevant section of code?
 
anand phulwani
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic