Using PHP as a Spring MVC View via Quercus (GO) _php tutorial

Source: Internet
Author: User
Original stickers:

http://blog.caucho.com/2009/04/14/using-php-as-a-spring-mvc-view-via-quercus/

This week, I ' ve been prepping for a talk on Quercus in which I promised to show a demo of Spring MVC using a PHP view. So, means that I actually had to do it. Turns out it is quite easy and PHP makes for a very nice, compact view technology for Spring MVC. This was a bit of tease since the code for this won ' t go out until at least next week, but since a number of people has been En asking for the while, I thought I ' d give a preview ...

First, let me show how it looks by using the sample "Imagedb" Application this ships with Spring. Here's a screenshot of the app in action:

Basically, you upload an image to the page and it keeps track of what you've uploaded in a database. Here is the JSP and PHP views Side-by-side:

}

} ?>

< table border="1" cellspacing="0" cellpadding="5"> < form action=" Imageupload " method=" POST " enctype=" Multipart/form-data ">

foreach ($images as $image) { ?> < table border="1" cellspacing="0" cellpadding="5">

</table> < P> <%%>

< table border="1" cellspacing="0" cellpadding="5"> < form action=" Imageupload " method=" POST " enctype=" Multipart/form-data ">

</form> </table>

"Cleardatabase" >clear database

< body> </table> < p> </form> </table>

"Cleardatabase" >clear database

<%@ page session="false"%> <%@ page import="Java.util.List, Java.util.Iterator, Org.springframework.samples.imagedb.ImageDescriptor"%>

< body>

<% List images = (list) request.getattribute("Images") ; for (Iterator it = Images.iterator(); It.hasnext(); { imagedescriptor image = (imagedescriptor) it. Next(); %> < table border="1" cellspacing="0" cellpadding="5">

"10%" >name <%= image.getname() %>
"2" > "imagecontent?name=<%= image.getname ()%>" height=">
Description (<%= image.getdescriptionlength() %>) <%= image.getshortdescription() %>
"10%" >name "Text" name="name">
Content "File" name="image">
Description "description" </span> cols=<span class= "St0" > "+" </span> rows=<span class= "St0" > "5" </ Span>>
"2" >"Submit" value="Upload image">
"10%" >name getName, $image () ?>
"2" > "Imagecontent?name= getName ()?>" height=">
Description ( = $image-getdescriptionlength() ?> ) getshortdescription, $image () ?>
"10%" >name "Text" name="name">
Content "File" name="image">
Description "description" </span> cols=<span class= "St0" > "+" </span> rows=<span class= "St0" > "5" </ Span>>
"2" >"Submit" value="Upload image">

Jsp:

<%@ page session= "false"%> <%@ page= "Java.util.List,"%>
    <%< span="">= (List) request.getattribute ("Images"  < span="">    < span="">  (Iterator it =< span="">=   < span=""> %>
    
 
Name <%= Image.getname ()%>
"Height=" >
Description (<%= image.getdescriptionlength ()%>) <%= image.getshortdescription ()%>

<%< span="">%>

Clear Database

< span="">

 
 
  < span="">< span="">(?>< span="">< span="">< span=""> 
      
  
  
Name
->getname ()?> "height=" >
Description ( ->getdescriptionlength ()?>)

?>

What I think is interesting between these, and the PHP, even though it ' s calling Java objects, has a simpl ER syntax. It's not a major issue, but you can see the PHP is as reasonable as any other view for Java.

Now how does you configure it? Just Add the Quercusview class to a urlbasedviewresolver and give a php suffix and you ' re-done:

    < span="">  < span="">  < span=""> < span="">< span="">< span="">< span="">< span="">< span="">< span="">< span="">< span="">< span="">< span=""><   c24>  < span="">  < span="">  < span="">  < span="">  < span="">< span=""> < span="">< span="">< span=""> < span="">< span="">< span=""> < span="">< span=""><   /c55> < span="">  < span=""> 

If you ' re interested in the implementation ... The view is pretty easy-connect up once I learned Spring ' s view API. It ' s essentially a servlet.service () call with a map of model values. So the Quercusview class above are just a modified quercusservlet that injects the model values as PHP globals. I ' m not sure so that's right just yet, but it's a start. The other option would is to put the values as PHP superglobals or in a specialized Spring array.

http://www.bkjia.com/PHPjc/626628.html www.bkjia.com true http://www.bkjia.com/PHPjc/626628.html techarticle Original stickers: Http://blog.caucho.com/2009/04/14/using-php-as-a-spring-mvc-view-via-quercus/This week, Ive been prepping For a talk on Quercus in which I promised to show a demo of SPR ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.