java静态页面框架,Spring MVC - 静态页面示例

以下示例演示如何使用Spring MVC Framework编写基于Web的简单应用程序,该框架可以借助 标记访问静态页面和动态页面。

首先,让我们使用一个可用的Eclipse IDE,并遵循以下步骤,使用Spring Web Framework开发基于动态表单的Web应用程序。

序号

描述

1

在Spring MVC - Hello World章节中解释,在com.codingdict包下创建一个名为HelloWeb的项目。

2

在com.codingdict包下创建一个Java类WebController。

3

在jsp子文件夹下创建一个静态文件final.htm。

4

更新WebContent / WEB-INF文件夹下的Spring配置文件HelloWeb-servlet.xml,如下所示。

5

最后一步是创建源文件和配置文件的内容并导出应用程序,如下所述。

WebController.java

package com.codingdict;

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.htm";

}

}

HelloWeb-servlet.xml

xmlns:xsi= " http://www.w3.org/2001/XMLSchema-instance"

xmlns:context= "http://www.springframework.org/schema/context"

xmlns:mvc= "http://www.springframework.org/schema/mvc"

xsi:schemaLocation= "http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-2.5.xsd

http://www.springframework.org/schema/mvc

http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-3.0.xsd">

这里, 标签用于映射静态页面。mapping属性必须是 Ant 模式

,用于指定http请求的URL模式。location属性必须指定一个或多个有效资源目录位置,其中包含静态页面,包括图像,样式表,JavaScript和其他静态内容。可以使用逗号分隔的值列表指定多个资源位置。

以下是Spring视图文件 WEB-INF / jsp / index.jsp的内容 。这将是一个登陆页面; 此页面将发送访问

staticPage服务方法 的请求,该 方法 将此请求重定向到WEB-INF / pages文件夹中可用的静态页面。

index.jsp

Spring Landing Page

Spring Landing Pag

Click below button to get a simple HTML page

final.htm

Spring Static Page

A simple HTML page

完成创建源文件和配置文件后,导出应用程序。右键单击您的应用程序,使用Export→WAR

File选项并将您的HelloWeb.war文件保存在Tomcat的webapps文件夹中。

现在,启动Tomcat服务器并确保您可以使用标准浏览器从webapps文件夹访问其他网页。现在尝试访问URL - http://

localhost:8080 / HelloWeb / index。如果Spring Web Application的一切正常,我们将看到以下屏幕。

11440454f95db1a46570934414d6e9eb.png

单击“获取HTML页面”按钮以访问staticPage服务方法中提到的静态页面。如果您的Spring Web应用程序一切正常,我们将看到以下屏幕。

9e0fab374204fee7cbe75b74289a260a.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值