在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java/ spring javaweb部署到公網(wǎng)以后,只能訪問JSP,訪問Servlet提

spring javaweb部署到公網(wǎng)以后,只能訪問JSP,訪問Servlet提示404

本地部署一切正常,可以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 />

<!-- 處理器映射器:該映射器根據(jù)URL來匹配bean的name,映射器都實(shí)現(xiàn)了接口HandlerMapping -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>

<!-- 處理器適配器:適配器都實(shí)現(xiàn)了HandlerAdapter,action按照適配器要求開發(fā),規(guī)則是實(shí)現(xiàn)Controller -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
    <!-- JSON轉(zhuǎn)換器 -->
    <property name="messageConverters">
        <list>
            <!--下面使用的是GSON,如若使用普通JSON,請(qǐng)使用MappingJackson2HttpMessageConverter-->
            <bean class="org.springframework.http.converter.json.GsonHttpMessageConverter"/>
        </list>
    </property>
</bean>
<bean class="com.kingsbet.wzry.WebConfig"></bean>
<!-- 視圖的解析器 :解析JSP視圖,默認(rèn)使用JSTL,要求classpath下有JSTL的JAR包-->
<!--<bean-->
        <!--class="org.springframework.web.servlet.view.InternalResourceViewResolver">-->
    <!--<property name="prefix" value="/page/"/>-->
    <!--<property name="suffix" value=".jsp"/>-->
<!--</bean>-->

</beans>

目錄結(jié)構(gòu)

clipboard.png

project structure

clipboard.png

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 打包項(xiàng)目后 本地訪問也出問題了,只能訪問JSP,不能訪問SERVLET

回答
編輯回答
伐木累

如果我沒記錯(cuò)的話,是要在tomcat的server.xml的配置文件中把你的域名加進(jìn)去

2018年2月27日 07:21
編輯回答
魚梓

解決了.一個(gè)深坑.
原因:用gradle war 命令打的war包,WEB-INF下沒有web.xml (將WAR包解壓后可看里面的內(nèi)容),而本地用TOMCAT打的包是有這個(gè)文件的.

解決辦法:將項(xiàng)目目錄中的web.xml ,移動(dòng)到WEB-INF下(我之前是在WEB-INF目錄外)

2017年3月25日 07:03