springMVC面試問題整理一

一:springMVC方面的css

    1;如何搭建springMVC框架
web

        1):下載spring源包 spring-framework-3.1.0.RELEASE-with-docs.zipspring

                下載spring的依賴包spring-framework-3.0.5.RELEASE-dependencies.zipapache

        2):導入dist目錄下面除了下面三個其他全部的包
mvc

                org.springframework.web.struts-3.1.0.RELEASE.jar
                org.springframework.spring-library-3.1.0.RELEASE.libd
                org.springframework.web.portlet-3.1.0.RELEASE.jar
app

                引入依賴包下com.springsource.org.apache.commons.logging-1.1.1.jar及com.springsource.org.aopalliance-1.0.0.jar框架

        3):spring的框架配置
jsp

            3.1)在web.xml裏面配置主要配置應用上下文配置,利用ContextLoadListener去加載spring的配置文件,第二個就是配置spring的核心servletDispatcherServlet,同時配置servlet的相應路徑,配置爲/所有過濾,若是有中文的話最好配置上他的字符集過濾器,
url

        ·<!-- 配置上下文,引入配置文件路徑-->
spa

            <context-param>

                    <param-name>contextConfigLocation</param-name>

                    <!-- 上下文引入配置文件,路勁-->

                    <param-value>/WEB-INF/spring-servlet.xml</param-value>

            </context-param>

            <!--  配置監聽器 -->

            <listener>

                    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

            </listener>

            <!-- 配置spring核心servlet-->

            <servlet>

                    <servlet-name>spring</servlet-name>

                    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

                    <load-on-startup>1</load-on-startup>

            </servlet>

            <servlet-mapping>

                    <servlet-name>spring</servlet-name>

                    <url-pattern>*.do</url-pattern>

            </servlet-mapping>

            <!-- 字符集過濾器 -->

            <filter>

                    <filter-name>encodingFilter</filter-name>

                    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

                    <init-param>

                            <param-name>encoding</param-name>

                             <param-value>UTF-8</param-value>

                    </init-param>

                    <init-param>

                            <param-name>forceEncoding</param-name>

                            <param-value>true</param-value>

                    </init-param>

            </filter>

            <filter-mapping>

                    <filter-name>encodingFilter</filter-name>

                    <url-pattern>/*</url-pattern>

            </filter-mapping>

            3.2):配置spring的配置文件,這裏是簡單的搭建一個springMVC框架,

                        若是是須要註解的,就配上開啓註解功能,同時須要配置你的包掃描的配置,靜態資源處理的一些配置

                        配置你的模型視圖解析,在請求是模型視圖名稱添加的先後綴。

                        <!-- 是否啓用註解-->

                        <mvc:annotation-driven />

                        <!-- 掃描的包的配置 -->

                        <context:component-scan base-package="*" />

                        <!-- 配置spring的視圖解析器,到時候返回添加的添加前置和後綴-->

                        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

                                <property name="prefix" value="/"></property>

                                <property name="suffix" value=".jsp"></property>

                        </bean>

                        <!-- 配置js、css、image等靜態資源直接映射到對應的文件夾,不被DispatcherServlet處理 location:資源所處實際位置,mapping:映射後訪問的相對路徑,[**]能夠跨目錄,[*]不能跨目錄 -->

                <mvc:resources location="/WEB-INF/resources/**" mapping="/resources/**" />

<mvc:resources location="/WEB-INF/resource/**" mapping="/resource/**" />

相關文章
相關標籤/搜索