Spring MVC在"/"上打开index.jsp [英] Spring MVC open index.jsp on "/"

查看:62
本文介绍了Spring MVC在"/"上打开index.jsp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用此URL http://localhost:8080/myApp/打开index.jsp,以及如何使用这样的超链接 <a href="/">HOME</a>并转到index.jsp(http://localhost:8080/myApp/)吗?

How can I open index.jsp using this url http://localhost:8080/myApp/and how can I use an hyperlink like this <a href="/">HOME</a> and go to index.jsp (http://localhost:8080/myApp/)?

这是我的web.xml:

Here's my web.xml:

<display-name>myApp</display-name>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/application-config.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>myApp</servlet-name>
    <servlet-class>
       org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>myApp</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

这是我的myApp-servlet.xml:

And here is my myApp-servlet.xml:

<context:component-scan base-package="org.myApp.com" />

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

提前谢谢!

推荐答案

只需添加具有适当处理程序方法的@Controller

Just add a @Controller with an appropriate handler method

@Controller
public class RootController {
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String root() {
        return "index";
    }
}

假设index.jsp/WEB-INF/view中.

这篇关于Spring MVC在"/"上打开index.jsp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆