(笔记)JSP中实现Java 代码--JSP的语法

本文介绍了在MyEclipse环境中创建JSP页面并正确显示中文字符的方法,详细解析了JSP脚本元素的不同用法及注意事项,包括如何设置pageEncoding属性以支持中文。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在MyEclipse中创建JSP,一下代码要将"pageEncoding=ISO-8859-1"更改为"gbk"才能显示中文字符
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>

在JSP-Script编写java程序主要语法规则:

[color=red](1)<% %>[/color]
For Example:

<body>
[color=red] <%[/color]
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
[color=red] %>[/color]
<%=format.format(date) %>

</body>

<% %>期间包裹着的是一个java代码....

[color=red](2)<%! %>[/color]
For Example

<body>
[color=red]<%![/color] Date date = new Date(); [color=red]%>[/color]
[color=red]<%![/color]SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); [color=red]%>[/color]
<%=format.format(date) %>

</body>

此处要注意的是:符号";",虽然有"<>"的包裹但是不能漏写,否则会报错。

[color=red](3)<%= %>[/color]此符号在前两个例子中已经运用相当于:
<%=format.format(date)%>
<%out.println(format.format(date));%>

两种方式对比:符号区别";" "="实际相当于"out.println()".注意不能在<%%>中添加"!",原因是<%out.println(format.format(date));%>是一段java代码,而不是变量和方法...

PS:在操作中发现<%%>可以代替<%! %>程序不会报错,但是反之则不可以...带求证...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值