struts1.x implementation of Studs MVC Framework-----php

Source: Internet
Author: User
Tags mkdir prepare symlink tld

JAKARTA struts structure porting the PHP development framework, using object-oriented development architecture and APIs, simulates an HTTP servlet container and uses the PHP Service page engine technology.

Download Address: http://mojavelinux.com/projects/studs/

The file structure is as follows:

As shown above, the files in Web-inf are the core files of the Studs framework (especially the files under Lib and TLD), where:

1.messages.properties file:







Welcome.title = Studs:: Welcome
Welcome.heading = Welcome to Studs!
Welcome.message = The application has been successfully installed!

Pageviews.message = This page has been viewed <strong>{ 0 }</strong> times.

2.struts-config.xml file:







? XML version= "1.0" encoding= "Iso-8859-1 " ?>
<! DOCTYPE struts-config Public "-//apache Software foundation//dtd struts Configuration 1.2//en"
"Http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd" >
<!--
This is a basic studs/struts configuration file with an example
Welcome Action/page and other commented sample elements.
-->
< Struts-config >

<!-- Example configuration of a database connection


&lt;data-sources&gt;


&lt;data-source type= "Horizon.sql.BasicDataSource" &gt;


&lt;set-property


property= "description"


Value= "Primary data source for localhost database"/&gt;


&lt;set-property


Property= "Driverclassname"


Value= "Horizon.sql.drivers.MySQLDriver"/&gt;


&lt;set-property


Property= "username"


value= "User"/&gt;


&lt;set-property


property= "Password"


Value= "Secret"/&gt;


&lt;set-property


property= "url"


Value= "Mysql://localhost/dbname"/&gt;


&lt;/data-source&gt;


&lt;/data-sources&gt;


-->

< Form-beans >
<!-- sample Form Bean descriptor for an actionform
<form-bean
Name= "Inputform"
Type= "app. Inputform "/>
-->
</ Form-beans >

< global-exceptions >
<!-- Sample Exception Handler
<exception
key= "Expired.password"
Type= "app. Expiredpasswordexception "
Path= "/changepassword.jsp"/>
-->
</ global-exceptions >

< Global-forwards >
<!-- Default forward to "welcome" action -->
< forward name = "Welcome" Path = "/welcome.do" />
</ Global-forwards >

< action-mappings >
<!-- Default "Welcome" action -->
< Action Path = "/welcome" forward = "/PAGES/WELCOME.PSP" />
< Action Path = "/example" forward = "/PAGES/EXAMPLE.PSP" />

<!-- Sample input and input submit actions





&lt;action


Path= "/input"


Type= "Org.apache.struts.actions.ForwardAction"


parameter= "/pages/input.jsp"/&gt;





&lt;action


Path= "/inputsubmit"


Type= "app. Inputaction "


Name= "Inputform"


Scope= "Request"


Validate= "true"


input= "/pages/input.jsp"/&gt;





&lt;action


Path= "/edit*"


Type= "app. Edit{1}action "


Name= "Inputform"


Scope= "Request"


Validate= "true"


input= "/pages/edit{1}.jsp"/&gt;





-->
</ action-mappings >

< Controller locale = "false" Inputforward = "true" />

< message-resources parameter = "/web-inf/messages.properties" />

</ Struts-config >

3.web.xml file:







? XML version= "1.0" encoding= "UTF-8 " ?>
<! DOCTYPE Web-app Public "-//sun Microsystems, INC.//DTD Web Application 2.3//en" "http://java.sun.com/dtd/web-app_2 _3.dtd " >
< Web-app >

< Display-name > Studs Basic Application </ Display-name >
< Description > a bare-bones foundation for creating a Web application based on the studs MVC framework+ </ Description >
< Context-param >
<!-- if Controlallresources is set, all files should being handled by the Stratus
container, including all non-php/html files -->
< Param-name > controlallresources </ Param-name >
< Param-value > false </ Param-value >
</ Context-param >

<!-- Servlet Definitions -->
< servlet >
< Servlet-name > default </ Servlet-name >
< Servlet-class > Stratus.servlets.DefaultServlet </ Servlet-class >
< Init-param >
< Param-name > Listings </ Param-name >
< Param-value > true </ Param-value >
</ Init-param >
< Load-on-startup > 1 </ Load-on-startup >
</ servlet >
< servlet >
< Servlet-name > Phase </ Servlet-name >
< Servlet-class > Phase.servlet.PhaseServlet </ Servlet-class >
< Init-param >
< Param-name > ScratchDir </ Param-name >
< Param-value > /web-inf/work </ Param-value >
</ Init-param >
< Init-param >
< Param-name > Tldresourcedir </ Param-name >
< Param-value > /web-inf/tld </ Param-value >
</ Init-param >
< Init-param >
< Param-name > Ignoreel </ Param-name >
< Param-value > false </ Param-value >
</ Init-param >
< Load-on-startup > 2 </ Load-on-startup >
</ servlet >
< servlet >
< Servlet-name > Action </ Servlet-name >
< Servlet-class > Studs.action.ActionServlet </ Servlet-class >
< Init-param >
< Param-name > Config </ Param-name >
< Param-value > /web-inf/struts-config.xml </ Param-value >
</ Init-param >
< Init-param >
< Param-name > Validating </ Param-name >
< Param-value > true </ Param-value >
</ Init-param >
< Load-on-startup > 3 </ Load-on-startup >
</ servlet >

<!-- Servlet Mappings -->
< servlet-mapping >
< Servlet-name > default </ Servlet-name >
< Url-pattern > / </ Url-pattern >
</ servlet-mapping >
< servlet-mapping >
< Servlet-name > Phase </ Servlet-name >
< Url-pattern > *.PSP </ Url-pattern >
</ servlet-mapping >
< servlet-mapping >
< Servlet-name > Action </ Servlet-name >
< Url-pattern > *.do </ Url-pattern >
</ servlet-mapping >

<!-- Mime Type Mappings -->
< mime-mapping >
< extension > HTML </ extension >
< Mime-type > text/html </ Mime-type >
</ mime-mapping >
< mime-mapping >
< extension > CSS </ extension >
< Mime-type > Text/css </ Mime-type >
</ mime-mapping >
< mime-mapping >
< extension > JS </ extension >
< Mime-type > Text/javascript </ Mime-type >
</ mime-mapping >
< mime-mapping >
< extension > PNG </ extension >
< Mime-type > Image/png </ Mime-type >
</ mime-mapping >
< mime-mapping >
< extension > jpg </ extension >
< Mime-type > Image/jpeg </ Mime-type >
</ mime-mapping >
< mime-mapping >
< extension > JPEG </ extension >
< Mime-type > Image/jpeg </ Mime-type >
</ mime-mapping >
< mime-mapping >
< extension > gif </ extension >
< Mime-type > Image/gif </ Mime-type >
</ mime-mapping >

<!-- Default Welcome File List -->
< welcome-file-list >
< Welcome-file > INDEX.PSP </ Welcome-file >
</ welcome-file-list >

</ Web-app >

4. Document Build.xml:







? XML version= "1.0" ?>
< Project name = "Studs Basic" Basedir =".. /.." default = "Package" >
< Property file =".. /.. /build.properties "   />

< Target name = "Package" depends = "Prepare" >
< mkdir dir =".. /.. /${release.dir}/${project.release.version} " />
< Tar DestFile =".. /.. /${release.dir}/${project.release.version}/studs-basic-${project.release.version}.tar.gz " Compression = "gzip" >
< Tarfileset dir ="." prefix = "Studs-basic" Defaultexcludes = "Yes" >
< Exclude name = "Classes/build.xml" />
< Exclude name = "**/todo" />
< Exclude name = "**/notes" />
</ Tarfileset >
</ Tar >
</ Target >

< Target name = "clean" >
<!-- Make sure to break symlinks -->
< symlink Action = "Delete" Link = "${basedir}/web-inf/lib" FailOnError = "No" />
< symlink Action = "Delete" Link = "${basedir}/web-inf/tld" FailOnError = "No" />

< Delete Includeemptydirs = "Yes" FailOnError = "No" >
< Fileset dir = "Web-inf/work" >
< include name ="**" />
</ Fileset >
< Fileset dir = "Web-inf/lib" >
< include name ="**" />
</ Fileset >
< Fileset dir = "Web-inf/tld" >
< include name ="**" />
</ Fileset >
</ Delete >
</ Target >

< Target name = "Prepare" depends = "clean" >
<!-- Create work Directory -->
< mkdir dir = "Web-inf/work" />
< chmod dir = "Web-inf/work" Perm = "0777" type = "dir" />
<!-- create lib directory and copy framework libraries -->
< mkdir dir = "Web-inf/lib" />
< Copy Todir = "Web-inf/lib" >
< Fileset dir =".. /.. /src " >
< include name ="**" />
</ Fileset >
</ Copy >
<!-- create TLD directory and copy known TLDs -->
< mkdir dir = "Web-inf/tld" />
< Copy Todir = "Web-inf/tld" >
< Fileset dir =".. /.. /conf/tld " >
< include name = "*.tld" />
</ Fileset >
</ Copy >
<!-- copy over the controller and server conf file -->
< Copy Todir ="." >
< Fileset dir =".. /.. /conf " >
< include name = "index.php" />
< include name = ". htaccess" />
</ Fileset >
</ Copy >
</ Target >
</ Project >

5.logging.properties file:







#  == Setup Log Appenders ==
#logging. Rootlogger = DEBUG , file
#logging. Appender.file = Horizon.util.logging.FileLogAppender
#logging. Appender.file.file = /tmp/studs-basic.log
#  == specific logging per category ==
#logging. Logger. [ Partial package or classname ] = DEBUG

Other files can basically be found in the skeleton source code.

The paging file is as follows:

1.index.php:







? PHP
error_reporting ( E_all );
Ini_set ( '' include_path '' ,   '' Web-inf/lib ''   . (Directory_separator ==   '' / ''   ?   '' : ''   :   '' ; '' )  .   '' web-inf/classes '' );
umask ( 0002 );

require_once   '' horizon/init.php '' ;

Import ( '' Stratus.connector.HttpProcessor '' );
Import ( '' Stratus.config.ContextConfig '' );

$config   =   &   New Contextconfig ( dirname ( __file__ ));
$processor   =   &   New Httpprocessor ( $config -> GetContext ());
$processor -> run ();
?>

2.INDEX.PSP:







<% ... @ Page language="php" %>
<% ... @ taglib uri="/web-inf/tld/phase-core.tld" Prefix="C " %>
<% ... @ taglib uri="/web-inf/tld/studs-html.tld" prefix= "html " %>
< C:redirect Context ="/" >< Html:rewrite forward = "Welcome" /></ C:redirect >

3.WELCOME.PSP:







<% ... @ Page language="php" %>
<% ... @ taglib uri="/web-inf/tld/phase-core.tld" Prefix="C " %>
<% ... @ taglib uri="/web-inf/tld/phase-fmt.tld" prefix ="fmt " %>
<% ... @ taglib uri="/web-inf/tld/studs-html.tld" prefix = " HTML "   %>
<! DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 strict//en"
"Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
< HTML xmlns = "http://www.w3.org/1999/xhtml" >
< Head >
< title >< Fmt:message Key = "Welcome.title"   /></ title >
< Meta http-equiv = "Content-type" content = "text/html charset=utf-8"   />
</ Head >
< Body >
< H3 >< Fmt:message Key = "Welcome.heading"   /></ H3 >
< P >< Fmt:message Key = "Welcome.message"   /></ P >
< P >< Html:link Action = "/example" > Click here </ Html:link > For an example of the template tag library. </ P >
< C:set var = "Welcomepageviewcount" value = "${applicationscope.welcomepageviewcount + 1}" Scope = "Application" />
< P style = "Font-size:small;" >< Fmt:message Key = "Pageviews.message" arg0 = "${applicationscope.welcomepageviewcount}" /></ P >
</ Body >
</ HTML >

4.EXAMPLE.PSP:







<% ... @ taglib uri="/web-inf/tld/studs-template.tld" prefix = " Template "   %>
<% ... @ taglib uri="/web-inf/tld/phase-string.tld" Prefix="str " %>
<% ... @ taglib uri="/web-inf/tld/phase-core.tld" prefix= "C " %>
< Template:insert Template = "/PAGES/TMPL/TEMPLATE.PSP" >
< Template:put name = "title" content = "Studs:: Template Taglib Example" Direct = "true" />
< Template:put name = "Heading" Direct = "true" > Template Taglib Example </ Template:put >
< Template:put name = "Intro" Direct = "true" >
This page demonstrates the studs template taglib.  The Content is inserted by the parent page either directly or via a include file. Below are two examples of content insertion.
</ Template:put >
< Template:put name = "Content" Direct = "true" >
< Str:replace Replace = "LF" with = "&lt;br/&gt;" > This text is specified inline using the template:put tag.

It also uses the Str:replace taglib to convert Endlines to BR tags.

I am also testing the conditional EL syntax. < Strong > ${2% 2? ' Odd ': ' Even '} </ Strong ></ Str:replace >
</ Template:put >
< Template:put name = "Content2" content = "/PAGES/TMPL/CONTENT.PSP"   />
</ Template:insert >

5.TEMPLATE.PSP:







<% ... @ taglib uri="/web-inf/tld/studs-html.tld" Prefix="html " %>
<% ... @ taglib uri="/web-inf/tld/studs-template.tld" prefix = " Template "   %>
<! DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 strict//en"
"Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
< HTML xmlns = "http://www.w3.org/1999/xhtml" Xml:lang = "en" Lang = "en" >
< Head >
< title >< Template:get name = "title"   /></ title >
</ Head >
< Body >
< H3 >< Template:get name = "Heading"   /></ H3 >
< P >< Template:get name = "Intro"   /></ P >
< P style = "border:1px dashed #999999; Background-color: #F0F0F0;" >
< Template:get name = "Content"   />
</ P >
< P style = "border:1px dashed #999999; Background-color: #F0F0F0;" >
< Template:get name = "Content2"   />
</ P >
< P > &laquo;   < Html:link forward = "Welcome" > Back </ Html:link ></ P >
</ Body >
</ HTML >

6.CONTENT.PSP:







This text comes from a include file using the Template:put tag.

Thus, a sample program based on the PHP studs Framework is completed. (Note: The appeal code is taken from the studs example)







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.