DOC

3096.docjava

By Jennifer Walker,2014-10-14 09:24
9 views 0
3096.docjava

    由于程序的原因,本文件未被完整保存。

    首页 ? 研究文集 ? 开发框架

    Jbuilder 7.0 开发Struts 项目

    sunxia 原创 (参与分!7967,专家分!50) 发表!2003-04-17 18:12 版本!1.0 阅读!7931

     首先,从http://jakarta.apache.org下载jakarta-struts-1.0.2.zip,解开后有两个主要目录libwebapps,里面包含有Struts.jar包,和一些标签。

    Jbuilder中建立工程newTest,新建newTest.jsp,logon.jsp.同时新建newTestForm.java,newTestAction.java

    接着为该工程引入,Struts.jar包,

    jakarta-struts-1.0.2.zip 解压后的lib 目录下的所有*.Tld文件考到工程的WEB-INF 目录下面, 修改web.xml文件!

    内容如下!

    <?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>

     <servlet>

     <servlet-name>action</servlet-name>

     <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>

     <init-param> <param-name>application</param-name>

     <param-value>org.apache.struts.webapp.example.ApplicationResources</param-value>

     </init-param>

     <init-param>

     <param-name>config</param-name>

     <param-value>/WEB-INF/struts-config.xml</param-value>

     </init-param>

     <init-param>

     <param-name>debug</param-name>

     <param-value>2</param-value>

     </init-param>

     <init-param>

     <param-name>detail</param-name>

     <param-value>2</param-value>

     </init-param>

     <init-param>

     <param-name>validate</param-name>

     <param-value>true</param-value>

     </init-param>

     <load-on-startup>2</load-on-startup>

     </servlet>

     <servlet-mapping>

     <servlet-name>action</servlet-name>

     <url-pattern>/</url-pattern>

     </servlet-mapping>

     <taglib>

     <taglib-uri>/WEB-INF/app.tld</taglib-uri>

     <taglib-location>/WEB-INF/app.tld</taglib-location>

     </taglib>

     <taglib>

     <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>

     <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>

     </taglib>

     <taglib>

     <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>

     <taglib-location>/WEB-INF/struts-html.tld</taglib-location>

     </taglib>

     <taglib>

     <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>

     <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>

     </taglib>

    </web-app>

建立struts-config.xml,内容如下!

    <?xml version="1.0" encoding="ISO-8859-1" ?>

    <!DOCTYPE struts-config PUBLIC

     "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"

     "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd"> <struts-config>

     <!-- ========== Form Bean Definitions =================================== -->

     <form-beans>

     <form-bean name="newTestForm"

     type="newtest. newTestForm"/>

     </form-beans>

     <!-- ========== Global Forward Definitions ============================== -->

     <global-forwards>

     <forward name="logon" path="/logon.jsp"/>

     </global-forwards>

     <!-- ========== Action Mapping Definitions ============================== -->

     <action-mappings>

     <action path="/logon"

     type="newtest.newTestAction"

     name="newTestForm"

     scope="request"

     validate="true"

     input="/logon.jsp">

     <!--forward name="logon" path="/logon.jsp"/-->

     </action>

     </action-mappings>

    </struts-config>

    package newtest;

import java.io.IOException;

    import java.util.Hashtable;

    import java.util.Locale;

    import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionServlet; import org.apache.struts.util.MessageResources;

    public class newTestAction extends Action {

     public newTestAction() {

     }

     public ActionForward perform(ActionMapping mapping,

     ActionForm form,

     HttpServletRequest request,

     HttpServletResponse response)

     throws IOException, ServletException

     {

     return (mapping.findForward("logon"));

     }

    }

++++++++++++++++++++++

    package newtest;

    import javax.servlet.http.HttpServletRequest;

    import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping;

    public class newTestForm extends ActionForm {

     public newTestForm() {

     }

     private String str;

     public String getStr() {

     return str;

     }

     public void setStr(String str) {

     this.str = str;

     }

     }

版权声明 本篇文章对您是否有帮助( 投票! 投票结果!

    作者其它文章!

    作者全部文章

     评论人!leilongdan 参与分: 12276 专家分: 325 发表时间: 2003-06-25 13:51

    那两个jsp文件怎么用(拜托作者写清楚点吧。尤其对于不太熟struts框架的人来说,需要例子得到感官认识。

这个文章共有 1 条评论,共 1

    上一篇文章 下一篇文章 返回〔开发框架〕

Report this document

For any questions or suggestions please email
cust-service@docsford.com