吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 559|回复: 3
收起左侧

[求助] springmvc求助

[复制链接]
无知到博学 发表于 2022-10-1 21:43
springMVC.xml文件里有
[Asm] 纯文本查看 复制代码
<mvc:default-servlet-handler/>

然后访问静态页面仍然出现 如图片

为什么?
屏幕截图 2022-10-01 214316.png

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

小丑恶人 发表于 2022-10-1 22:48
1、查看 web.xml 中对 springDispatcherServlet 的配置
2、未给控制器层添加注解@Controller
3、访问的页面(如index.html)位置错误,未放于webapp文件夹下
4、在springMvc的配置文件中添加上mvc:default-servlet-handler/以及mvc:annotation-driven/
5、
<resources>
            <resource>
                <directory>src/main/java</directory>
                <!--所在的目录-->
                <includes>
                    <!--包括目录下的.properties,.xml 文件都会被扫描到->
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.*</include>
                </includes>
            </resource>
        </resources>
 楼主| 无知到博学 发表于 2022-10-2 09:16
小丑恶人 发表于 2022-10-1 22:48
1、查看 web.xml 中对 springDispatcherServlet 的配置
2、未给控制器层添加注解@Controller
3、访问的页 ...

web.xml
[Java] 纯文本查看 复制代码
<servlet>
    <servlet-name>survey</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:**/spring-mvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
中的
控制器层有注解@Controller
访问页面地址是对的
mvc:default-servlet-handler/以及mvc:annotation-driven/也添加了


跳转到静态页面和控制层,都会出现no mapping for get......   ,如果跳转到jsp是可以的
会不会是web.xml中<param-value>classpath:**/spring-mvc.xml</param-value>问题
小丑恶人 发表于 2022-10-2 12:52
无知到博学 发表于 2022-10-2 09:16
web.xml[mw_shl_code=java,true]
    survey
    org.springframework.web.servlet.DispatcherServlet
...

那应该就是默认是jsp后缀,你要修改配置文件支持html后缀

<!-- jsp配置-->
<bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!--<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />-->
        <property name="viewClass"  value="com.ssm.HtmlResourceView" />
        <property name="prefix" value="/" />  
        <property name="suffix" value=".jsp" />
        <property name="order" value="1" />
    </bean>

    <!--html配置-->
    <bean id="htmlviewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="com.ssm.HtmlResourceView"/>
        <property name="order" value="2" />
        <property name="prefix" value="/"/>
        <property name="suffix" value=".html" />
        <property name="contentType" value="text/html;charset=UTF-8"></property>
    </bean>
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-3 16:55

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表