电脑安全

您当前的位置:主页 > 电脑安全 >

Studs MVC Framework-----PHP的Struts1.X实现-网络编程

来源:[db:来源]标题:   文件    编辑:电脑技术全能网 时间:2019-09-21 12:23

原标题:Studs MVC Framework-----PHP的Struts1.X实现-网络编程
   Jakarta Struts构造移植过去的PHP开辟框架,应用面向工具的开辟构造和API,模仿了一个HTTP Servlet容器和应用了PHP效劳页面引擎技巧。下载地点:http://mojavelinux.com/projects/studs/文件构造以下:如上图,WEB-INF中的文件都是Studs框架的中心文件(特别是lib和tld下的文件),此中:1.messages.properties文件:welcome.title=Studs::Welcomewelcome.heading=WelcometoStuds!welcome.message=Theapplicationhasbeensuccessfullyinstalled!pageviews.message=Thispagehasbeenviewed<strong>{0}</strong>times.2.struts-config.xml文件:<?xmlversion="1.0"encoding="ISO-8859-1"?><!DOCTYPEstruts-configPUBLIC"-//ApacheSoftwareFoundation//DTDStrutsConfiguration1.2//EN""http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd"><!--ThisisabasicStuds/Strutsconfigurationfilewithanexamplewelcomeaction/pageandothercommentedsampleelements.--><struts-config><!--exampleconfigurationofadatabaseconnection<data-sources><data-sourcetype="horizon.sql.BasicDataSource"><set-propertyproperty="description"value="Primarydatasourceforlocalhostdatabase"/><set-propertyproperty="driverClassName"value="horizon.sql.drivers.MySQLDriver"/><set-propertyproperty="username"value="user"/><set-propertyproperty="password"value="secret"/><set-propertyproperty="url"value="mysql://localhost/dbname"/></data-source></data-sources>--><form-beans><!--sampleformbeandescriptorforanActionForm<form-beanname="inputForm"type="app.InputForm"/>--></form-beans><global-exceptions><!--sampleexceptionhandler<exceptionkey="expired.password"type="app.ExpiredPasswordException"path="/changePassword.jsp"/>--></global-exceptions><global-forwards><!--Defaultforwardto"welcome"action--><forwardname="welcome"path="/welcome.do"/></global-forwards><action-mappings><!--Default"welcome"action--><actionpath="/welcome"forward="/pages/welcome.psp"/><actionpath="/example"forward="/pages/example.psp"/><!--sampleinputandinputsubmitactions<actionpath="/Input"type="org.apache.struts.actions.ForwardAction"parameter="/pages/Input.jsp"/><actionpath="/InputSubmit"type="app.InputAction"name="inputForm"scope="request"validate="true"input="/pages/Input.jsp"/><actionpath="/edit*"type="app.Edit{1}Action"name="inputForm"scope="request"validate="true"input="/pages/Edit{1}.jsp"/>--></action-mappings><controllerlocale="false"inputForward="true"/><message-resourcesparameter="/WEB-INF/messages.properties"/></struts-config>3.web.xml文件:<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEweb-appPUBLIC"-//SunMicrosystems,Inc.//DTDWebApplication2.3//EN""http://java.sun.com/dtd/web-app_2_3.dtd"><web-app><display-name>StudsBasicApplication</display-name><description>Abare-bonesfoundationforcreatingawebapplicationbasedontheStudsMVCFramework+</description><context-param><!--ifcontrolAllResourcesisset,allfilesshouldbehandledbythestratuscontainer,includingallnon-php/htmlfiles--><param-name>controlAllResources</param-name><param-value>false</param-value></context-param><!--ServletDefinitions--><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><!--ServletMappings--><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><!--MimeTypeMappings--><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><!--DefaultWelcomeFileList--><welcome-file-list><welcome-file>index.psp</welcome-file></welcome-file-list></web-app>4.文件build.xml:<?xmlversion="1.0"?><projectname="StudsBasic"basedir="../.."default="package"><propertyfile="../../build.properties"/><targetname="package"depends="prepare"><mkdirdir="../../${release.dir}/${project.release.version}"/><tardestfile="../../${release.dir}/${project.release.version}/studs-basic-${project.release.version}.tar.gz"compression="gzip"><tarfilesetdir="."prefix="studs-basic"defaultexcludes="yes"><excludename="classes/build.xml"/><excludename="**/TODO"/><excludename="**/NOTES"/></tarfileset></tar></target><targetname="clean"><!--makesuretobreaksymlinks--><symlinkaction="delete"link="${basedir}/WEB-INF/lib"failonerror="no"/><symlinkaction="delete"link="${basedir}/WEB-INF/tld"failonerror="no"/><deleteincludeemptydirs="yes"failonerror="no"><filesetdir="WEB-INF/work"><includename="**"/></fileset><filesetdir="WEB-INF/lib"><includename="**"/></fileset><filesetdir="WEB-INF/tld"><includename="**"/></fileset></delete></target><targetname="prepare"depends="clean"><!--createworkdirectory--><mkdirdir="WEB-INF/work"/><chmoddir="WEB-INF/work"perm="0777"type="dir"/><!--createlibdirectoryandcopyframeworklibraries--><mkdirdir="WEB-INF/lib"/><copytodir="WEB-INF/lib"><filesetdir="../../src"><includename="**"/></fileset></copy><!--createtlddirectoryandcopyknowntlds--><mkdirdir="WEB-INF/tld"/><copytodir="WEB-INF/tld"><filesetdir="../../conf/tld"><includename="*.tld"/></fileset></copy><!--copyoverthecontrollerandserverconffile--><copytodir="."><filesetdir="../../conf"><includename="index.php"/><includename=".htaccess"/></fileset></copy></target></project>5.logging.properties文件:#==Setuplogappenders==#logging.rootLogger=DEBUG,file#logging.appender.file=horizon.util.logging.FileLogAppender#logging.appender.file.file=/tmp/studs-basic.log#==Specificloggingpercategory==#logging.logger.[partialpackageorclassname]=DEBUG其余文件基础上都能够在框架源代码中找到。页面文件以下:1.index.php:<?phperror_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=&newContextConfig(dirname(__FILE__));$processor=&newHttpProcessor($config->getContext());$processor->run();?>2.index.psp:<%...@pagelanguage="php"%><%...@tagliburi="/WEB-INF/tld/phase-core.tld"prefix="c"%><%...@tagliburi="/WEB-INF/tld/studs-html.tld"prefix="html"%><c:redirectcontext="/"><html:rewriteforward="welcome"/></c:redirect>3.welcome.psp:<%...@pagelanguage="php"%><%...@tagliburi="/WEB-INF/tld/phase-core.tld"prefix="c"%><%...@tagliburi="/WEB-INF/tld/phase-fmt.tld"prefix="fmt"%><%...@tagliburi="/WEB-INF/tld/studs-html.tld"prefix="html"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><title><fmt:messagekey="welcome.title"/></title><metahttp-equiv="Content-Type"content="text/html;charset=UTF-8"/></head><body><h3><fmt:messagekey="welcome.heading"/></h3><p><fmt:messagekey="welcome.message"/></p><p><html:linkaction="/example">Clickhere</html:link>foranexampleofthetemplatetaglibrary.</p><c:setvar="welcomePageViewCount"value="${applicationScope.welcomePageViewCount+1}"scope="application"/><pstyle="font-size:small;"><fmt:messagekey="pageviews.message"arg0="${applicationScope.welcomePageViewCount}"/></p></body></html>4.example.psp:<%...@tagliburi="/WEB-INF/tld/studs-template.tld"prefix="template"%><%...@tagliburi="/WEB-INF/tld/phase-string.tld"prefix="str"%><%...@tagliburi="/WEB-INF/tld/phase-core.tld"prefix="c"%><template:inserttemplate="/pages/tmpl/template.psp"><template:putname="title"content="Studs::TemplateTaglibExample"direct="true"/><template:putname="heading"direct="true">TemplateTaglibExample</template:put><template:putname="intro"direct="true">Thispagedemonstratestheuseofthestudstemplatetaglib.Contentisinsertedbytheparentpageeitherdirectlyorviaanincludefile.Belowaretwoexamplesofcontentinsertion.</template:put><template:putname="content"direct="true"><str:replacereplace="LF"with="&lt;br/&gt;">Thistextwasspecifiedinlineusingthetemplate:puttag.Italsousesthestr:replacetaglibtoconvertendlinestoBRtags.IamalsotestingtheconditionalELsyntax.<strong>${2%2?''odd'':''even''}</strong></str:replace></template:put><template:putname="content2"content="/pages/tmpl/content.psp"/></template:insert>5.template.psp:<%...@tagliburi="/WEB-INF/tld/studs-html.tld"prefix="html"%><%...@tagliburi="/WEB-INF/tld/studs-template.tld"prefix="template"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"xml:lang="en"lang="en"><head><title><template:getname="title"/></title></head><body><h3><template:getname="heading"/></h3><p><template:getname="intro"/></p><pstyle="border:1pxdashed#999999;background-color:#F0F0F0;"><template:getname="content"/></p><pstyle="border:1pxdashed#999999;background-color:#F0F0F0;"><template:getname="content2"/></p><p>&laquo;<html:linkforward="welcome">Back</html:link></p></body></html>6.content.psp:Thistextcomesfromanincludefileusingthetemplate:puttag.如许,一个基于PHP Studs框架的示例顺序就实现了。(注:上诉代码取自studs自带的例子)

上一篇:php 判断上传图大小函数-网络编程

下一篇:没有了