bsf*_*ira 1 java spring jsp servlets spring-mvc
如何使用此url打开index.jsp http://localhost:8080/myApp/
,如何使用这样的超链接
<a href="/">HOME</a>
转到index.jsp(http://localhost:8080/myApp/
)?
这是我的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>
Run Code Online (Sandbox Code Playgroud)
这是我的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>
Run Code Online (Sandbox Code Playgroud)
提前致谢!
只需添加一个@Controller
适当的处理程序方法
@Controller
public class RootController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public String root() {
return "index";
}
}
Run Code Online (Sandbox Code Playgroud)
假设index.jsp
在/WEB-INF/view
.
归档时间: |
|
查看次数: |
11028 次 |
最近记录: |