tomcat - Jsessionid 出现在 url 中间

标签 tomcat spring-mvc jsessionid

我正在使用: Spring MVC 3.0, Apache 瓷砖 2.1.2, Apache 汤姆猫 6.0.29, 道场 1.5

当我的浏览器第二次访问 Tomcat 时,该 url 被塞满了,中间出现了一个 jsessionid。

例如

第一个请求:http://localhost:8081/accessmenus/menus/main

第二个请求:http://localhost:8081/;jsessionid=45A05E88DD78A06B1C99C3C02D45D65Caccessmenus/menus/main

(所有后续请求都没有jsessionid)

有什么想法吗?

web.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
         version="2.4">

  <!-- The master configuration file for this Spring web application -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/config/web-application-config.xml</param-value>
  </context-param>

  <!-- Enables use of HTTP methods PUT and DELETE -->
  <filter>
    <filter-name>httpMethodFilter</filter-name>
    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>httpMethodFilter</filter-name>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
  </filter-mapping>

  <!-- Loads the Spring web application context -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <!-- The front controller of this Spring Web application, responsible for handling all application requests -->
  <servlet>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value></param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <!-- Map all *.spring requests to the DispatcherServlet for handling -->
  <servlet-mapping>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

</web-app>

webmvc-config.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:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <!-- Enables controllers mapped with @RequestMapping annotations, formatting annotations @NumberFormat @DateTimeFormat, and JSR 303 style validation -->
    <mvc:annotation-driven/>

    <mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/web-resources/" />
    <mvc:default-servlet-handler />

    <!-- Map paths directly to view names without controller processing. Use the view-name attribute if necessary: by convention the view name equals the path without the leading slash -->
    <mvc:view-controller path="/" view-name="mmg" />

    <!-- Resolves logical view names returned by Controllers to Tiles; a view name to resolve is treated as the name of a tiles definition -->
    <bean id="tilesViewResolver" class="org.springframework.js.ajax.AjaxUrlBasedViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
    </bean>

    <!-- Configures the Tiles layout system -->
    <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/**/views.xml</value>
            </list>
        </property>
    </bean>

</beans>

Tomcat server.xml:

<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">

  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <Listener className="org.apache.catalina.core.JasperListener" />
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

  <GlobalNamingResources>
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <Service name="Catalina">

    <Connector port="8081" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"
               compression="on"
               compressableMimeTypes="text/html,text/xml,text/plain,text/javascript,text/css"
               compressionMinSize="1024" />

    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

    <Engine name="Catalina" defaultHost="localhost">

      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="false"
            xmlValidation="false" xmlNamespaceAware="false">

        <Context docBase="ROOT" path=""/>

      </Host>
    </Engine>
  </Service>
</Server>

最佳答案

事实证明,这是由我在我的一个 JSP 中进行的意外双 urlencoding 引起的。本质上,我是这样做的:

<spring:url var="rootPath" value="/root/path" />
<spring:url var="fullPath" value="${rootPath}/rest/of/path" />

我不应该使用 spring:url 来创建初始的“rootPath”变量,因为它会对它进行 urlencode。这是完成它的方法:

<c:set var="rootPath" value="/root/path" scope="page" />
<spring:url var="fullPath" value="${rootPath}/rest/of/path" />

感谢那些花时间阅读我的问题的人! :^)

关于tomcat - Jsessionid 出现在 url 中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4620381/

相关文章:

tomcat - tomcat 7中的类加载

java - 指向 env var 的 jboss 缓存位置

java - 我正在尝试 Spring MVC,当我在 Controller 类中添加 @Autowired 时,出现以下错误 :

spring - 如何使用 Spring HATEOAS 更改 HAL 链接格式

tomcat - 登录后如何刷新JSESSIONID cookie

Spring MVC 将上传的 MultipartFile 保存到特定文件夹

tomcat - 生产中的 Grails 3 Asset Pipeline 产生错误的 URL 和 404ing

java - 路径变量不映射 Spring MVC

tomcat - 如何在反向代理后面正确设置 JSESSIONID cookie 路径

javascript - Angular 2 没有在后续请求中传递 JSESSIONID