分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

JstlView

发布时间:2023-09-06 01:43责任编辑:彭小芳关键词:暂无标签

一:InternalResourceViewResolver

1.InternalResourceViewResolver

  JSP是常见的视图技术,可以使用InternalResourceViewResolver作为视图解析器。

二:JstlView

1.JstlView说明

  如果项目中使用了JSTL。

  InternalResourceViewResolver会将InternalResourceView转为JstlView。

2.fmt标签说明

  如果使用fmt标签。

  需要在springmvc配置文件中配置国际化资源文件。

三:程序

1.添加jstl需要的lib包

  

2.添加配置文件

  

3.success

  需要导入fmt标签库。

 1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 ????pageEncoding="utf-8"%> 3 <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 5 <html> 6 <head> 7 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 8 <title>Insert title here</title> 9 </head>10 <body>11 ????success page12 ????<br><br>13 ????<fmt:message key="i18n.username"></fmt:message><br>14 ????<br>15 ????<fmt:message key="i18n.password"></fmt:message><br>16 </body>17 </html>

4.配置国际化资源文件

 1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 ????xmlns:context="http://www.springframework.org/schema/context" 4 ????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 5 ????xsi:schemaLocation="http://www.springframework.org/schema/beans ?????6 ???????????????????????http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 7 ???????????????????????http://www.springframework.org/schema/context ?8 ???????????????????????http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 9 ????<!-- 配置自定义扫描的包 --> ??????????????10 ????<context:component-scan base-package="com.spring.it" ></context:component-scan>11 ????12 ????<!-- 配置视图解析器 -->13 ????<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">14 ????????<property name="prefix" value="/WEB-INF/views/" />15 ??????????<property name="suffix" value=".jsp" />16 ????</bean>17 ????18 ????<!-- 配置国际化资源文件 -->19 ????<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">20 ????????<property name="basename" value="i18n"></property>21 ????</bean>22 </beans>

5.controller

 1 package com.spring.it; 2 ?3 import org.springframework.stereotype.Controller; 4 import org.springframework.web.bind.annotation.RequestMapping; 5 ?6 @Controller 7 public class HelloWorldControl { 8 ????@RequestMapping("/helloworld") 9 ????public String hello() {10 ????????System.out.println("hello world*");11 ????????return "success";12 ????}13 }

6.index

 1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 ????pageEncoding="utf-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <title>Insert title here</title> 8 </head> 9 <body>10 ????<a href="helloworld">Test Jstl</a>11 </body>12 </html>

7.效果

  

  

JstlView

原文地址:https://www.cnblogs.com/juncaoit/p/8476397.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved