【问题标题】:How to point to html files in different location?如何指向不同位置的html文件?
【发布时间】:2013-09-05 16:27:27
【问题描述】:

我的情况是这样的:

MyApplication(folder)
|
| - server (folder)
|      |
|      | - some structure (folder)
|      |     |
|            | - login.jsp
|
| - client (folder) 
|     |
|     | - clientSoftware (folder)
|     |     |
|     |     | - index.html
|     |     | - something.html
|     |     | - otherSomething.html

我在 Apache Tomcat 服务器上运行它,我想得到的是:

localhost:8080/NameOfApplication/index.html

而不是 localhost:8080/NameOfApplication/client/clientSoftware/index.html

我正在使用 spring mvc。有没有办法做到这一点?

【问题讨论】:

  • 您正在使用 Spring MVC 和 Apache 服务器...我希望它是 Apache Tomcat 对,请清楚,因为如果您只使用 Apache Web 服务器,那么我认为您不会剩下任何解决方案...
  • 好吧,当然,对不起。只是纠正它=)

标签: java spring-mvc


【解决方案1】:

看看这个example,特别是第 6 部分。

<bean name="/welcome.htm" .
     class="com.mkyong.common.controller.HelloWorldController" />

请注意,当他声明 bean 时,web url 现在是 http://localhost:8080/SpringMVC/welcome.htm

【讨论】:

  • 我认为这可以解决问题。我会尽快测试:)。谢谢
【解决方案2】:

好吧,在 Spring MVC 中,如果你使用的是 Annotation,那么,

举个例子,

HTML

<a href="cabBooking">Book Cab</a>

弹簧控制器

@Controller
public class HomeController {

@RequestMapping(value="/cabBooking", method = RequestMethod.GET)
    public ModelAndView getCabBookingPage() {

        ModelAndView mnv = new ModelAndView("cabBooking"); //here it will search "cabBooking.jsp" in /WEB-INF/pages/ and same mapping you can find in dispatcher file.

此外,无论您调用此函数的映射是什么,用户都可以看到,实际页面就是您将要执行的页面 返回 mnv;

   }
}

调度程序文件

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    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
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <context:annotation-config />
    <context:component-scan base-package="com.on.transport" />
    <mvc:annotation-driven />

    <bean
       class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/pages/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

</beans>

在 web.xml 中添加 Spring MVC Dispatcher 类映射。查看任何 Spring MVC 示例以了解 web.xml 更改。

【讨论】:

    猜你喜欢
    • 2013-07-09
    • 2021-06-01
    • 1970-01-01
    • 2016-01-06
    • 2011-12-22
    • 1970-01-01
    • 2012-07-09
    • 2017-11-17
    • 1970-01-01
    相关资源
    最近更新 更多