Java 系列之spring學習--springmvc搭建(四)

來源:互聯網
上載者:User

標籤:intern   ted   jar包下載   val   targe   cat   tco   ica   star   

一、建立java Web 專案

  

二、添加jar包

  spring jar包http://repo.spring.io/release/org/springframework/spring/

  

   2.1、匯入jar包

    

    先不管哪些包的具體作用,直接全部匯入。

    

三、配置web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app>  <display-name>Archetype Created Web Application</display-name>  <!-- 所有的請求都會被dispatherservlet捕獲 -->  <servlet>    <servlet-name>springmvc</servlet-name> <init-param>  <param-name>contextConfigLocation</param-name>  <param-value>/WEB-INF/springmvc-servlet.xml</param-value>  </init-param>    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>    <load-on-startup>1</load-on-startup>  </servlet>  <servlet-mapping>  <servlet-name>springmvc</servlet-name>  <url-pattern>/</url-pattern>  </servlet-mapping></web-app>
四、建立一個控制器
package springmvc;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.web.servlet.ModelAndView;import org.springframework.web.servlet.mvc.AbstractController;public class welcomeController extends AbstractController {@Overrideprotected ModelAndView handleRequestInternal(HttpServletRequest arg0,HttpServletResponse arg1) throws Exception {// TODO Auto-generated method stubSystem.out.print("hello springmvc");return null;}}

五、建立springmvc-servlet.xml
<?xml version="1.0" encoding="UTF-8"?><beans   xmlns="http://www.springframework.org/schema/beans"      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"      xmlns:tx="http://www.springframework.org/schema/tx"      xmlns:context="http://www.springframework.org/schema/context"        xmlns:mvc="http://www.springframework.org/schema/mvc"        xsi:schemaLocation="http://www.springframework.org/schema/beans       http://www.springframework.org/schema/beans/spring-beans-3.2.xsd       http://www.springframework.org/schema/tx       http://www.springframework.org/schema/tx/spring-tx-3.2.xsd      http://www.springframework.org/schema/context      http://www.springframework.org/schema/context/spring-context-3.2.xsd      http://www.springframework.org/schema/mvc      http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">     <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean><bean name="/welcome.html" class="springmvc.welcomeController"></bean> <!-- 視圖解釋類 -->      <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">          <property name="prefix" value="/WEB-INF/JSP/"/>          <property name="suffix" value=".jsp"/>      </bean>  </beans>
六、Look

 

 

Java 系列之spring學習--springmvc搭建(四)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.