Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 有没有办法在春季将一个URL映射到另一个URL?_Java_Spring_Web Applications_Configuration - Fatal编程技术网

Java 有没有办法在春季将一个URL映射到另一个URL?

Java 有没有办法在春季将一个URL映射到另一个URL?,java,spring,web-applications,configuration,Java,Spring,Web Applications,Configuration,在Struts 1中,您可以在Struts-config.xml中使用如下声明: <action path="/first" forward="/second.do"> 我知道我可能会使事情复杂化,我应该坚持简单的事情来完成工作,但我希望这更像是一种陈述:“这个URL实际上是另一个URL的快捷方式(或别名)”(不要问为什么……说来话长……)通过ParameterableViewController可以看到,但不能完全看到 那么,这可能吗 谢谢大家! 我对Spring MVC不够熟悉

在Struts 1中,您可以在Struts-config.xml中使用如下声明:

<action path="/first" forward="/second.do">
我知道我可能会使事情复杂化,我应该坚持简单的事情来完成工作,但我希望这更像是一种陈述:“这个URL实际上是另一个URL的快捷方式(或别名)”(不要问为什么……说来话长……)通过
ParameterableViewController
可以看到,但不能完全看到

那么,这可能吗


谢谢大家!

我对Spring MVC不够熟悉,不知道在那里做你想做的事情的最简单方法。但是,通过实现,可以轻松设置将一个url转发到另一个url的规则。

通过实现,可以轻松地指定“此url实际上是指向此其他url的快捷方式(或别名)”,并使实现包含一个属性,该属性是应重定向或转发到其他url的url的映射


在XML中,您只需为这个拦截器添加一个bean,并配置它哪些URL应该重定向到什么,并将对拦截器的引用添加到SimpleRullHandlerMapping的拦截器属性。

我建议在Spring配置文件之外管理基于URL的规则?保持Spring配置文件干净,并在外部重写/管理URL。看一看

我希望有帮助


-florin

我最终创建了一个单独的URL处理程序映射,将URL别名组合在一起。然后,我对包含的映射进行了非常详细的描述,例如:

<bean id="theDummyController" class="org.springframework.web.servlet.mvc.ParameterizableViewController">
     <property name="viewName" value="forward:second.do"/>
</bean>

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
  <property name="mappings">
    <props>
      <prop key="/first.do">theDummyController</prop>
      <prop key="/second.do">theController</prop>
      ...
<bean id="aliasUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
  <description>
    <![CDATA[
      The following URLs are in fact shortcuts (or aliases) 
      to other URLs etc etc (...I'll spare you the ugly part)
    ]]>
  </description>
  <property name="mappings">
    <props>
      <prop key="/first.do">theController</prop>
      ...

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
  <property name="mappings">
    <props>
      <prop key="/second.do">theController</prop>
      ...


我还想添加一个拦截器,捕捉一个URL并将其转发给另一个URL,然后返回false以中断执行链。但是,处理程序映射是否必须解析传入请求的执行链?只有这样,DispatcherServlet才会执行返回链中的处理程序和拦截器。因此,我必须将URL映射到“某物”,然后让拦截器处理其余内容。但是我应该把它映射到什么呢?实际上我不确定处理程序是否需要对每个URL进行映射,然后才能将其映射到拦截器,但是如果需要:映射*到404页面(未找到),那么您应该很好。。。
<bean id="aliasUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
  <description>
    <![CDATA[
      The following URLs are in fact shortcuts (or aliases) 
      to other URLs etc etc (...I'll spare you the ugly part)
    ]]>
  </description>
  <property name="mappings">
    <props>
      <prop key="/first.do">theController</prop>
      ...

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
  <property name="mappings">
    <props>
      <prop key="/second.do">theController</prop>
      ...