最简单的表单提交(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>test1title>

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

 

 

  <servlet>

    <servlet-name>actionservlet-name>

    <servlet-class>org.apache.struts.action.ActionServletservlet-class>

    <init-param>

      <param-name>configparam-name>

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

    init-param>

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

 servlet>

 

 

 

  <servlet-mapping>

    <servlet-name>actionservlet-name>

    <url-pattern>*.dourl-pattern>

  servlet-mapping>

 

 

 

  <welcome-file-list>

    <welcome-file>index.jspwelcome-file>

  welcome-file-list>

 

    <taglib>

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

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

      taglib>

   

      <taglib>

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

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

      taglib>

   

      <taglib>

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

        <taglib-location>

你可能感兴趣的:(java面试)