少年阿賓

          那些青春的歲月

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

          //web.xml

          <?xml version="1.0" encoding="UTF-8"?>
          <web-app xmlns:xsi="  <display-name>struts</display-name>
           
            <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/classes/struts-config.xml</param-value>
              </init-param>
              <init-param>
                <param-name>debug</param-name>
                <param-value>3</param-value>
              </init-param>
              <init-param>
                <param-name>detail</param-name>
                <param-value>3</param-value>
              </init-param>
              <load-on-startup>0</load-on-startup>
            </servlet>
           
             <servlet-mapping>
               <servlet-name>action</servlet-name>
               <url-pattern>*.do</url-pattern>
             </servlet-mapping>
           
           <!--  
             <jsp-config>
              <taglib>
               <taglib-uri>/WEB-INF/struts-html</taglib-uri>
               <taglib-location>WEB-INF/struts-html.tld</taglib-location>
              </taglib>
              <taglib>
               <taglib-uri>/WEB-INF/struts-bean</taglib-uri>
               <taglib-location>WEB-INF/struts-bean.tld</taglib-location> 
              </taglib> 
              <taglib>
               <taglib-uri>/WEB-INF/struts-logic</taglib-uri>
               <taglib-location>WEB-INF/struts-logic.tld</taglib-location>
              </taglib> 
             
             </jsp-config>
            -->  
           
            <welcome-file-list>
              <welcome-file>index.html</welcome-file>
              <welcome-file>index.htm</welcome-file>
              <welcome-file>index.jsp</welcome-file>
              <welcome-file>default.html</welcome-file>
              <welcome-file>default.htm</welcome-file>
              <welcome-file>default.jsp</welcome-file>
            </welcome-file-list>
          </web-app>

           

           

          //struts-config.xml這個放置在src目錄下面

          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "

          <struts-config>
            <form-beans >
              <form-bean name="userForm" type="com.abin.struts1.form.UserForm" ></form-bean>
            </form-beans>
            <global-exceptions />
            <global-forwards />
            <action-mappings >
              <action
                path="/userAction"
                type="com.abin.struts1.action.UserAction"
                name="userForm"
                parameter="method"
                scope="request"
                validate="true"
                input="/add.jsp"
                >
                <forward name="add" path="/index.jsp"/>
             </action>
            </action-mappings>
            <message-resources parameter="com.yourcompany.struts.ApplicationResources" />
          </struts-config>

           

           

           

          //UserAction.java

          package com.abin.struts1.action;

          import javax.servlet.http.HttpServletRequest;
          import javax.servlet.http.HttpServletResponse;

          import org.apache.struts.action.ActionForm;
          import org.apache.struts.action.ActionForward;
          import org.apache.struts.action.ActionMapping;
          import org.apache.struts.actions.DispatchAction;

          import com.abin.struts1.form.UserForm;

          public class UserAction extends DispatchAction {

           public ActionForward user(ActionMapping mapping, ActionForm form,
             HttpServletRequest request, HttpServletResponse arg3) throws Exception {
            UserForm userForm = (UserForm) form;
            String un = userForm.getUsername();
            String pw = userForm.getPassword();
            
            System.out.println("username="+un);
            System.out.println("password="+pw);
            
            return mapping.findForward("add");
           }

          }

           

           

          //UserForm.java

          package com.abin.struts1.form;

          import org.apache.struts.action.ActionForm;

          public class UserForm extends ActionForm{
           private int id;
           private String username;
           private String password;
           
           public int getId() {
            return id;
           }
           public void setId(int id) {
            this.id = id;
           }
           public String getUsername() {
            return username;
           }
           public void setUsername(String username) {
            this.username = username;
           }
           public String getPassword() {
            return password;
           }
           public void setPassword(String password) {
            this.password = password;
           }
           
           
          }

           

           

          //index.jsp這個放置在WebContent下面(我這里使用的eclipse,如果是Myeclipse就直接放置在WebRoot下面)

          <%@ page language="java" contentType="text/html; charset=utf-8"
              pageEncoding="utf-8"%>
          <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
          <html>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
          <title>struts1.3 test</title>
          </head>
          <body>
           <a href="add.jsp" target="_blank" >新增</a>
          </body>
          </html>

           

           

          //add.jsp這個放置在WebContent下面(我這里使用的eclipse,如果是Myeclipse就直接放置在WebRoot下面)

          <%@ page language="java" contentType="text/html; charset=utf-8"
              pageEncoding="utf-8"%>
          <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
          <html>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
          <title>struts1.3 test</title>
          </head>
          <body>
           <form action="userAction.do" method="post">
            <input type="hidden" name="method" value="user" />
            用戶名:<br/>
            <input type="text" name="username" id="username" /><br/>
            密碼:<br/>
            <input type="text" name="password" id="password" /><br/>
            <input type="submit" value="提交" />
            <input type="reset" value="重置"/>
           
           </form>
          </body>
          </html>


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 东阿县| 沧州市| 亳州市| 孙吴县| 房山区| 方正县| 平安县| 衡东县| 新龙县| 惠州市| 正宁县| 福安市| 恩施市| 保山市| 黄大仙区| 潍坊市| 班戈县| 师宗县| 贺兰县| 日土县| 那曲县| 孟村| 钟祥市| 武冈市| 松溪县| 榆树市| 宜兰市| 玉门市| 纳雍县| 布拖县| 新建县| 和硕县| 银川市| 平乐县| 丹东市| 九龙坡区| 阜城县| 汝城县| 石泉县| 慈溪市| 江门市|