0

我的情况是这样的:

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

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

本地主机:8080/NameOfApplication/index.html

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

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

4

2 回答 2

1

看一下这个例子,特别是第 6 部分。

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

http://localhost:8080/SpringMVC/welcome.htm注意当他声明 bean 时web url 现在是怎样的。

于 2013-09-05T16:37:05.663 回答
0

Well, In Spring MVC, If you are using Annotation then,

As an Example,

HTML

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

Spring Controller

@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.

Also, whatever your mapping is to invoke this function will be visible to user and actual page is what you will p return mnv;

   }
}

dispatcher file

<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>

Add Spring MVC Dispatcher class mapping in web.xml. Have a look at any Spring MVC example for web.xml changes.

于 2013-09-05T18:29:59.250 回答