<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項目,我們在這里寫一個簡單的Servlet,測試一下。 ### 1.在src/main/java下,新建一個Servlet ~~~ package com.deppon.text01.action; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class UserServlet extends HttpServlet { private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request , response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=utf-8"); String action = request.getParameter("action"); if("login_input".equals(action)) { request.getRequestDispatcher("login.jsp").forward(request , response); } else if("login".equals(action)) { String name = request.getParameter("name"); String password = request.getParameter("password"); System.out.println("name->" + name + ",password->" + password); } } } ~~~ ### 2. 修改web.xml ~~~ <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <servlet> <servlet-name>UserServlet</servlet-name> <servlet-class>com.deppon.text01.action.UserServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>UserServlet</servlet-name> <url-pattern>/user</url-pattern> </servlet-mapping> </web-app> ~~~ ### 3. 新建JSP 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>Hello Maven</title> </head> <body> <p>大家好!</p> <a href="user?action=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="user?action=login" method="post"> Name:<input type="text" name="name" /> Password:<input type="password" name="password" /> <input type="submit" value="登錄" /> </form> </body> </html> ~~~ ### 4. 測試 ![](https://box.kancloud.cn/2016-09-06_57ce64fb49091.png) ![](https://box.kancloud.cn/2016-09-06_57ce64fb625f8.png) ![](https://box.kancloud.cn/2016-09-06_57ce64fb79f29.png) 項目結構如下圖所示: ![](https://box.kancloud.cn/2016-09-06_57ce64fb8cb56.png) 其實,構建完成之后,開發的話,應該和平時開發Web項目是一樣的。 2013-04-28 日修改 之前忘記說明pom文件了,需要添加依賴的: pom.xml ~~~ <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>test01</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>test01 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> <!-- 添加Servlet --> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> </dependencies> <build> <finalName>test01</finalName> </build> </project> ~~~ 很抱歉,之前忘記寫了. ps:希望之前看過的朋友再看一下哦 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - [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>

                              哎呀哎呀视频在线观看