配置看着都是对的 但是springmvc就是不执行controller层

我講你知 2021-05-10 01:29:49
这是spring配置:
<?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:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--开启注解驱动-->
<mvc:annotation-driven />
<!--扫描包-->
<context:component-scan base-package="com.zyl.controller" />
<!--视图解析器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>


web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">

<!-- springmvc的前端控制器 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>


controller:


启动tomcat能启动成功


但是一访问controller:直接404 连方法都没有执行(后台没有输出信息)


大佬们救命啊!!!
...全文
306 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
我講你知 2021-05-12
  • 打赏
  • 举报
回复
https://blog.csdn.net/u012596797/article/details/114993124 参照三、最终解决方案解决问题
qq_39936465 2021-05-11
  • 打赏
  • 举报
回复
引用 3 楼 我講你知 的回复:
[quote=引用 2 楼 qq_39936465 的回复:][quote=引用 楼主 我講你知 的回复:]这是spring配置: 但是一访问controller:直接404 连方法都没有执行(后台没有输出信息) 大佬们救命啊!!!
缺少项目名称 http://localhost:8080/项目名称/test[/quote] tomcat配置的直接是/ 而且能够启动成功应该是不差这个项目名的[/quote] 404就是页面资源没找到,基本就是路径问题,也就是说在你提供的映射下找不到test。jsp,跟你项目启动成功没关系,
  • 打赏
  • 举报
回复
可以看下:File ->Project Settings -> Model
我講你知 2021-05-10
  • 打赏
  • 举报
回复
引用 1 楼 得一以生 的回复:
<url-pattern>/</url-pattern>改成<url-pattern>/*</url-pattern>试试
不得行呀
我講你知 2021-05-10
  • 打赏
  • 举报
回复
引用 2 楼 qq_39936465 的回复:
[quote=引用 楼主 我講你知 的回复:]这是spring配置: 但是一访问controller:直接404 连方法都没有执行(后台没有输出信息) 大佬们救命啊!!!
缺少项目名称 http://localhost:8080/项目名称/test[/quote] tomcat配置的直接是/ 而且能够启动成功应该是不差这个项目名的
qq_39936465 2021-05-10
  • 打赏
  • 举报
回复
引用 楼主 我講你知 的回复:
这是spring配置: 但是一访问controller:直接404 连方法都没有执行(后台没有输出信息) 大佬们救命啊!!!
缺少项目名称 http://localhost:8080/项目名称/test
得一以生 2021-05-10
  • 打赏
  • 举报
回复
<url-pattern>/</url-pattern>改成<url-pattern>/*</url-pattern>试试

67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧