zoukankan      html  css  js  c++  java
  • java_Struts学习例子

    ***book.jsp***
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="/tags/struts-html" prefix="html" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Logon</title>
    </head>
    <body>
    <html:form action="/user/bookAction" focus="userId"><br>
     BookId:<html:text property="bookId" maxlength="10"/><br>
     
     BookName:<html:text property="bookName" maxlength="20"/><br>
     
     <html:submit>logon</html:submit>
    </html:form>
    </body>
    </html>
     
    ***BookForm.java***
    package cn.com.chengang.sms.user;
    import org.apache.struts.action.ActionForm;
    public class BookForm extends ActionForm
    {
     private String bookId;
     private String bookName;
     
     public String getBookId()
     {
      return this.bookId;
     }
     public void setBookId(String bookId)
     {
      this.bookId=bookId;
     }
     
     public String getBookName()
     {
      return this.bookName;
     }
     public void setBookName(String bookName)
     {
      this.bookName=bookName;
     }
    }

    ***BookAction.java***
    package cn.com.chengang.sms.user;
    import org.apache.struts.action.*;
    import javax.servlet.http.*;
    public class BookAction extends Action
    {
     public ActionForward execute(
       ActionMapping mapping,
       ActionForm form,
       HttpServletRequest request,
       HttpServletResponse response
       ) throws Exception
     {
      BookForm bf=(BookForm)form;
      String bookId=bf.getBookId();
      String bookName=bf.getBookName();
      
      return mapping.findForward("booksuccess");
     }
    }
     
    ***struts-config.xml ***
    <?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">
     
    <struts-config>

        <form-beans>
       
            <form-bean
                name="userForm"
                type="cn.com.chengang.sms.user.UserForm"/>
               
            <form-bean
       name="bookForm"
       type="cn.com.chengang.sms.user.BookForm"/>
        </form-beans>
       
       
        <action-mappings>
            <action
                path="/user/logonAction"
                type="cn.com.chengang.sms.user.LogonAction"
                name="userForm"
                scope="request">
         <forward name="success" path="/user/success.jsp"/>
         <forward name="fail" path="/user/fail.jsp"/>
         </action>
         
         <action
                path="/user/bookAction"
                type="cn.com.chengang.sms.user.BookAction"
                name="bookForm"
                scope="request">
         <forward name="booksuccess" path="/user/booksuccess.jsp"/>
         </action>
        </action-mappings>
        <message-resources parameter="cn.com.chengang.sms.MessageResources" />

    </struts-config>
     
     
    ***web.xml***
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE web-app
      PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
      "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
    <web-app>
      <display-name>SMS Application</display-name>
     
      <!-- Standard Action Servlet Configuration (with debugging) -->
      <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>
        <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>
        <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>

      <!-- Struts Tag Library Descriptors -->
      <taglib>
        <taglib-uri>/tags/struts-bean</taglib-uri>
        <taglib-location>/WEB-INF/tlds/struts-bean.tld</taglib-location>
      </taglib>
      <taglib>
        <taglib-uri>/tags/struts-html</taglib-uri>
        <taglib-location>/WEB-INF/tlds/struts-html.tld</taglib-location>
      </taglib>
      <taglib>
        <taglib-uri>/tags/struts-logic</taglib-uri>
        <taglib-location>/WEB-INF/tlds/struts-logic.tld</taglib-location>
      </taglib>
      <taglib>
        <taglib-uri>/tags/struts-nested</taglib-uri>
        <taglib-location>/WEB-INF/tlds/struts-nested.tld</taglib-location>
      </taglib>
      <taglib>
        <taglib-uri>/tags/struts-tiles</taglib-uri>
        <taglib-location>/WEB-INF/tlds/struts-tiles.tld</taglib-location>
      </taglib>
    </web-app>
  • 相关阅读:
    简单区间dp
    【题解】石子合并
    【2019.7.6】刷题记录
    【题解】大朋友的数字
    【基础】dp系列1
    【题解】垃圾陷阱
    【题解】导弹拦截
    hadoop各组件安装(非专业人士,不定期更新)
    python逼格提升
    python第三十二天-----算法
  • 原文地址:https://www.cnblogs.com/linsond/p/1738285.html
Copyright © 2011-2022 走看看