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

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ### **3.4.1需求** 創建一個web工程,實現入門程序的功能。 1)添加index.jsp,輸出hello world 2)添加一個servlet轉發到jsp頁面。 第一步:創建maven工程 ![](https://box.kancloud.cn/c96146d2199a7a3d0c74341f60320514_806x714.png) ![](https://box.kancloud.cn/833be518931350d25cdc5c6a3f7810b3_807x149.png) 添加webapp文件夾 ![](https://box.kancloud.cn/03cc8e6d04d3027f99348dee0626ccee_719x279.png) ![](https://box.kancloud.cn/c4051cf454d18f6a7a44f237ba92b687_283x332.png) ![](https://box.kancloud.cn/58c9ad9559383033b31e00bfb7b1f450_458x566.png) ![](https://box.kancloud.cn/8221eb2adb0c9b3e63eae2e1dd960342_878x630.png) ![](https://box.kancloud.cn/619465c98b2516c91569bfa2dda354d4_978x518.png) 第二步:pom文件添加依賴 ~~~ <?xml version="1.0" encoding="UTF-8"?> <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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>cn.li</groupId> <artifactId>web</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <version>2.0</version> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.4.14.v20181114</version> <configuration> <httpConnector> <port>8080</port> </httpConnector> <webApp> <contextPath>/my</contextPath> </webApp> </configuration> </plugin> </plugins> </build> </project> ~~~ 3.web.xml里內容 ~~~ <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <servlet> <servlet-name>myServlet</servlet-name> <servlet-class>cn.li.MyServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>myServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app> ~~~ 4.MyServlet里面內容 ~~~ public class MyServlet extends HttpServlet { @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setAttribute("msg","hello"); req.getRequestDispatcher("/index.jsp").forward(req,resp); } @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doPost(req, resp); } } ~~~ 5.編寫jsp ~~~ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <html> <head> <title>Insert title here</title> </head> <body> ${msg} </body> </html> ~~~ 6.運行 ①Run-- ![](https://box.kancloud.cn/763800386d8c6982393f3c2833b09ba5_1063x633.png) ![](https://box.kancloud.cn/138e4d75638e69c710aa0eb109a61459_586x142.png) ②tomcat插件運行 pom.xml文件中加入 ~~~ <build> <!--插件位置--> <plugins> <plugin> <!--tomcat7配置--> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <!-- or if you want to use tomcat 6.x <artifactId>tomcat6-maven-plugin</artifactId> --> <version>2.2</version> <configuration> <port>8080</port> <path>/</path> </configuration> </plugin> </plugins> </build> ~~~ 然后按下圖運行 ![](https://box.kancloud.cn/8a6fd2e223abe5267654e3b59ccd9659_360x406.png) ③jetty服務器運行 ~~~ <build> <plugins> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.4.14.v20181114</version> <configuration> <httpConnector> <port>8080</port> </httpConnector> <webApp> <contextPath>/my</contextPath> </webApp> </configuration> </plugin> </plugins> </build> ~~~ 和tomcat7同理運行 ### 補充:如果頁面出現${msg} 解決:1.~~~ //jsp頁面加 <%@ isELIgnored="false"%> ~~~ 2.web.xml開頭換成3.1版本 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> ~~~ 補充:maven官網:http://maven.apache.org/ tomcat插件:https://tomcat.apache.org/maven-plugin-2.2/run-mojo-features.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>

                              哎呀哎呀视频在线观看