<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之旅 廣告
                學習springMVC,我們來記錄下第一個HelloWord的程序 首先,我們組織需要的jar包 ~~~ commons-logging-1.1.3.jar spring-aop-4.1.7.RELEASE.jar spring-beans-4.1.7.RELEASE.jar spring-context-4.1.7.RELEASE.jar spring-core-4.1.7.RELEASE.jar spring-expression-4.1.7.RELEASE.jar **spring-web-4.1.7.RELEASE.jar spring-webmvc-4.1.7.RELEASE.jar** ~~~ 主要是引入了2個MVC的jar包。 下面我們來配置web.xml ~~~ <!-- The front controller of this Spring Web application, responsible for handling all application requests --> <servlet> <servlet-name>springDispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:application.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- Map all requests to the DispatcherServlet for handling --> <servlet-mapping> <servlet-name>springDispatcherServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> ~~~ 這里我們配置了DispatcherServlet類,然后< url-pattern>/ < /url-pattern>攔截所有請求。 再來看下application.xml ~~~ <context:component-scan base-package="com.gp.springmvc"></context:component-scan> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/pages/"></property> <property name="suffix" value=".jsp"></property> </bean> ~~~ 配置掃描注解的路徑 注入InternalResourceViewResolver類,通過此類,我們可以匹配到要展示的JSP頁面,通過prefix指定JSP所屬目錄,通過suffix指定文件的后綴名。 我們來看下后臺類 ~~~ @Controller public class HelloWorld { @RequestMapping("/sayHello") public String sayHello(){ System.out.println("hello world!!!"); return "success"; } } ~~~ 配置@Controller表示控制器,就是將此類注入到spring的容器中。 @RequestMapping(“/sayHello”)表示要被攔截的方法,后續我們會有細致的分析,這里我們就理解為定義什么名,那我們在訪問的時候就訪問這個名,就可以找到這個方法。 JSP頁面 ~~~ <a href="sayHello">sayHello</a> ~~~ 在鏈接中輸入sayHello,后臺會直接攔截請求,找到配置為@RequestMapping(“/sayHello”)的方法,執行。 方法return “success”;,后臺會根據application.xml的配置找到對應目錄的JSP 如圖,目錄結構 ![這里寫圖片描述](https://box.kancloud.cn/2016-03-15_56e7afc21b717.jpg "") 功能跳轉到success.jsp ~~~ <body> <h4>Hello world!!!</h4> </body> ~~~ 部署程序,運行127.0.0.1:8080/springMVC_01/index.jsp,查看結果。
                  <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>

                              哎呀哎呀视频在线观看