javascript
spring mvc入门示例教程-凯发k8官方网
以下示例显示如何使用spring mvc framework编写一个简单的基于web的应用程序,它可以使用
完整的项目文件结构如下所示 -
webcontroller.java 的代码如下所示 -
package com.yiibai.springmvc;import org.springframework.stereotype.controller; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.requestmethod;@controller public class webcontroller {@requestmapping(value = "/index", method = requestmethod.get)public string index() {return "index";}@requestmapping(value = "/staticpage", method = requestmethod.get)public string redirect() {return "redirect:/pages/final.html";} }java
staticpages-servlet.xml 的代码如下所示 -
xml
这里使用
下面是spring视图文件web-inf/jsp/index.jsp的内容。这将是一个登录页面,此页面将发送一个请求访问staticpage服务方法,该方法将此请求重定向到web-inf/pages文件夹中的静态页面。
index.jsp 页面的代码如下 -
<%@ page contenttype="text/html; charset=utf-8"%> <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>spring landing page
点击下面的按钮获得一个简单的html页面
html
final.html 的完整代码如下 -
a simple html page
html
完成创建源和配置文件后,导出应用程序。右键单击应用程序,并使用导出> war文件选项,并将文件保存为helloweb.war 在tomcat的webapps文件夹中。
现在启动tomcat服务器,现在尝试访问url => http://localhost:8080/helloweb/index 。 如果spring web应用程序没有问题,应该看到以下结果:
单击“获取html页面”按钮访问staticpage服务方法中提到的静态页面。如果spring web应用程序没有问题,应该看到以下结果:
原文出自【易百教程】,商业转载请联系作者获得授权,非商业转载请保留原文链接:https://www.yiibai.com/spring_mvc/springmvc_static_pages.html
总结
以上是凯发k8官方网为你收集整理的spring mvc入门示例教程--静态页面跳转的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇:
- 下一篇: