[java]springmvc中controller路由出现404
[java]springmvc中controller路由出现404
可能原因有很多
核对idea配置
mac: idea->File -> Project Structure
最重要的是 Artifacts,默认配置不对需要手动添加lib包
核对编译配置
mac: idea -》Run -》Edit Configurations -》 点绿色的+号,选择 tomcat–>local -》出现弹窗
弹窗配置server
弹窗配置Deployment
<!-- web/WEB-INF/web.xml 重要! 否则controller新的路由会出现404
修改 url-pattern 标签 修改前: <url-pattern>*.form</url-pattern> 修改后: <url-pattern>/</url-pattern>-->
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<!-- <url-pattern>*.form</url-pattern>-->
<url-pattern>/</url-pattern>
</servlet-mapping>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
// <!--支持注解,例如@Controller,对应src下controller的包名-->
<context:component-scan base-package="com.ah" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
// <!-- 配置JSP页面的位置:比如controller中return "hi" 对应文件位置是 /web/template/hi.jsp -->
<property name="prefix">
<value>/template/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>