本地部署一切正常,可以JSP也可以访问到servlet
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<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>
</filter>
<filter-mapping>
<filter-name>EncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--<param-value>classpath*:config/spring/spring-servlet.xml</param-value>-->
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/kingsbet/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:config/spring/spring-*.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
</web-app>
spring-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: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.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-3.0.xsd">
<context:component-scan base-package="com.kingsbet.wzry"/>
<mvc:default-servlet-handler />
<!-- 处理器映射器:该映射器根据URL来匹配bean的name,映射器都实现了接口HandlerMapping -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
<!-- 处理器适配器:适配器都实现了HandlerAdapter,action按照适配器要求开发,规则是实现Controller -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<!-- JSON转换器 -->
<property name="messageConverters">
<list>
<!--下面使用的是GSON,如若使用普通JSON,请使用MappingJackson2HttpMessageConverter-->
<bean class="org.springframework.http.converter.json.GsonHttpMessageConverter"/>
</list>
</property>
</bean>
<bean class="com.kingsbet.wzry.WebConfig"></bean>
<!-- 视图的解析器 :解析JSP视图,默认使用JSTL,要求classpath下有JSTL的JAR包-->
<!--<bean-->
<!--class="org.springframework.web.servlet.view.InternalResourceViewResolver">-->
<!--<property name="prefix" value="/page/"/>-->
<!--<property name="suffix" value=".jsp"/>-->
<!--</bean>-->
</beans>
目录结构
project structure
http://localhost:8080/kingsbet/userlogin servlet可以访问
http://localhost:8080/index.jsp jsp可以访问
http://xxx.xxx.xxx.xxx:8080/kingsbet/userlogin 不可以访问 提示404
http://xxx.xxx.xxx.xxx:8080/index.jsp jsp可以访问
tip1:先部署本地后,本地均可以访问 .用 gradle war 打包项目后 本地访问也出问题了,只能访问JSP,不能访问SERVLET
如果我没记错的话,是要在tomcat的server.xml的配置文件中把你的域名加进去