<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                在前兩篇博客中,使用Maven構建了Web項目,在這篇博客中寫一下,怎樣構建一個簡單的Struts2項目。 在準備過程中發現,要使用好Maven,個人覺得要好好利用這兩個網站: [http://mvnrepository.com/](http://mvnrepository.com/) [http://search.maven.org/](http://search.maven.org/) 由于自己對Maven的理解不是非常深,所以學習的時候遇到很多簡單的問題都沒法解決![委屈](https://box.kancloud.cn/2016-01-25_56a5a367bba9a.gif) ,走了很多彎路 ### 1. 新建一個基本的Web項目 這和前面講的是一樣的,可以參考前面的博客 ### 2. 添加Struts2依賴 這里主需要在pom.xml中添加一個struts-core的依賴即可: ~~~ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.deppon.demo</groupId> <artifactId>test02</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>test02 Maven Webapp</name> <url>http://maven.apache.org</url> <!-- 屬性配置 --> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <!-- 添加JUnit --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <!-- Struts2 依賴 --> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-core</artifactId> <version>2.3.1</version> </dependency> </dependencies> <build> <finalName>test02</finalName> </build> </project> ~~~ 之后,Maven會自動從網上下載struts2需要的其他依賴包,可以看一下這里: ![](https://box.kancloud.cn/2016-09-06_57ce64fbb0294.png) 是不是都有了,有的時候Maven可能會報錯,由于網絡的原因(個人認為大多是網絡問題,導致下載依賴包出錯![難過](https://box.kancloud.cn/2016-01-18_569ca449b6adc.gif) ),可以從上面提到的兩個網站手動下載 ### 3. 新建一個Action ~~~ package com.deppon.test02.action; import com.opensymphony.xwork2.ActionSupport; public class UserAction extends ActionSupport { private static final long serialVersionUID = -1417237614181805435L; private String name; private String password; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } /** * 跳轉到登錄界面 * @return */ public String login_input() { return SUCCESS; } /** * 登錄 * @return */ public String login() { System.out.println("name->" + name); System.out.println("password->" + password); return SUCCESS; } } ~~~ struts.xml ~~~ <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.i18n.encoding" value="utf-8"></constant> <constant name="struts.multipart.maxSize" value="20971520"/> <constant name="struts.devMode" value="true" /> <package name="p_user" namespace="/" extends="struts-default"> <action name="login_input" class="com.deppon.test02.action.UserAction" method="login_input"> <result name="success"> /login.jsp </result> </action> <action name="login" class="com.deppon.test02.action.UserAction" method="login"> <result name="success"> /login_success.jsp </result> </action> </package> </struts> ~~~ web.xml ~~~ <!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> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app> ~~~ index.jsp ~~~ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!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=UTF-8"> <title>主頁</title> </head> <body> <a href="login_input">去登陸</a> </body> </html> ~~~ login.jsp ~~~ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!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=UTF-8"> <title>登錄界面</title> </head> <body> <form action="login" method="post"> name:<input type="text" name="name" /> password:<input type="password" name="password" /> <input type="submit" value="登錄" /> </form> </body> </html> ~~~ login_success.jsp ~~~ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> <!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=UTF-8"> <title>登錄成功</title> </head> <body> <s:form action="login" namespace="/" method="post"> <s:textfield name="name" label="name"></s:textfield> <s:password name="password" label="password"></s:password> <s:submit value="Login"></s:submit> </s:form> </body> </html> ~~~ 項目結構如下圖所示: ![](https://box.kancloud.cn/2016-09-06_57ce64fbcefb4.png) --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - [Maven學習(一)- 環境搭建](http://blog.csdn.net/jolingogo/article/details/8775046) - [Maven學習(二)- 安裝m2eclipse插件?](http://blog.csdn.net/jolingogo/article/details/8796410) - [Maven學習(三)- 使用Maven構建Web項目](http://blog.csdn.net/jolingogo/article/details/8796726) - [Maven學習(四)- 使用Maven構建Web項目-測試](http://blog.csdn.net/jolingogo/article/details/8797153) - [Maven學習(五)- 使用Maven構建Struts2項目](http://blog.csdn.net/jolingogo/article/details/8798052) - [Maven學習(六)- 構建Hibernate項目](http://blog.csdn.net/jolingogo/article/details/8798684) - [Maven學習(七)- 構建Spring項目](http://blog.csdn.net/jolingogo/article/details/8799307) - [Maven學習(八)- 構建MyBatis項目](http://blog.csdn.net/jolingogo/article/details/8801158) - [Maven學習(九)- 構建SSH項目](http://blog.csdn.net/jolingogo/article/details/8811817) - [Maven學習(十) - 階段小結 ](http://blog.csdn.net/jolingogo/article/details/8821375) - [專欄:Maven學習之旅](http://blog.csdn.net/column/details/yuguiyang-maven.html)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看