最简单的表单提交(struts1.1实现)

最简单的表单提交(struts1.1实现)

技术 2009-07-25 17:57:24 阅读106 评论0   字号: 订阅

    一.建立工程

        1.创建一个Tomcat工程,起名字叫test。

         2.在根目录下创建index.jsp和jsp文件夹。jsp文件夹里创建一个test.jsp的文件。

         3.在WEB-INF文件夹下创建struts-config.xml和web.xml文件。并将struts所附带的标签struts-bean.tld,struts-html.tld和struts-logic.tld拷入。

         4.将struts附带的struts.jar以及10个common-*.jar的文件拷入lib文件夹下。

         5.在src文件夹下创建action和form文件夹。分别在这两个文件夹下创建ButtonAction.java和ButtonForm.java。

     二.添加程序

         1.index.jsp      

<%@ page language="java" contentType="text/html; charset=utf-8" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<html>

<head>

<title>

test Hellozhu!

</title>

</head>

<body>

 

<html:form action="/buttontest">

 

 <table>

  <tr>

    <td>

        <html:text property="name" size="40" maxlength="50"/>

    </td>

    <td>

       <html:submit value="apply"/>

    </td>

  </tr>

 </table>

</html:form>

 

</body>

</html>

       2. test.jsp    

<%@ page language="java" contentType="text/html; charset=windows-31j"

    pageEncoding="windows-31j"%>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-31j">

<title>test1</title>

</head>

<body>

Mr. <bean:write name="btform" property="name"/>, welcome!

</body>

</html>

 

   3.struts-config.xml

     

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts-config PUBLIC

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

          "http://struts.apache.org/dtds/struts-config_1_3.dtd">

<struts-config>

    <form-beans>

       <form-bean name="btform" type="form.ButtonForm"></form-bean>

    </form-beans>

   

    <global-exceptions>

      

    </global-exceptions>

   

    <global-forwards>

      

    </global-forwards>

   

    <action-mappings>

       <action path="/buttontest"

              type="action.ButtonAction"

              name="btform"

              input="index.jsp">  

       <forward name="success" path="/jsp/test.jsp"/>         

       </action>

    </action-mappings>

   

</struts-config>

     4.web.xml

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

  <!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>Struts Blank Application</display-name>

 

  <!-- Standard Action Servlet Configuration -->

  <servlet>

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

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

    <init-param>

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

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

    </init-param>

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

 </servlet>

 

 

  <!-- Standard Action Servlet Mapping -->

  <servlet-mapping>

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

    <url-pattern>*.do</url-pattern>

  </servlet-mapping>

 

 

  <!-- The Usual Welcome File List -->

  <welcome-file-list>

    <welcome-file>index.jsp</welcome-file>

  </welcome-file-list>

 

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

信息安全与项目管理

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值