当前位置:文档之家› JSP实例学习100例

JSP实例学习100例


</body> </html>
Error.jsp
<%@ page contentType="text/html;charset=GB2312" isErrorPage="true" %> <%@ page import="java.io.PrintWriter" %>
<html> <head> <title>CH4 - Error.jsp</title> </head> <body>
<h2>ㄏノ Big5?????タ?陪ボ?ㄇいゅ?</h2>
<% out.println("Щ??福そ?"); %>
</body> </html>
<% out.println("一个生僻的字:?"); %>
</body> </html>
10、使用 Big5 编码
<%@ page contentType="text/html;charset=Big5" %>
<html> <head>
<title> Big5.jsp</title> </head> <body>
<%@ page contentType="text/html;charset=gb2312" import="java.util.*" %> <HTML> <HEAD> <META NAME="GENERATOR" Content="NetObjects ScriptBuilder 3.0"> <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1"> <TITLE>Document Title</TITLE> </HEAD> <BODY> <center><font color=blue size=10 face="隶书"> <% Date today = new Date(); int hours = today.getHours(); int minute = today.getMinutes(); if(hours>=0 && hours<12){ out.println("早上好!"); }else{ out.println("下午好!"); }
<h2>Quoting 范例程序 3</h2>
<% out.println("JSP 遇到 \'、\"、\\、&lt;%、%\> 时需要做适当的修改"); %>
</body> </html>
7、简单计数器
<%@ page contentType="text/html; charset=gb2312" %> <%@ page language="java" %> <% Integer count = null;
2、c:out 标记输出
<%@ page contentType="text/html;charset=GB2312" %> <%@ taglib prefix="c" uri="/jsp/jstl/core" %>
<html> <head> <title>CH3 - HelloJSP.jsp</title> </head> <body>
<% out.println("不会执行 !!!"); %>
Quoting2.jsp
<%@ page contentType="text/html;charset=GB2312" %> <html> <head> <title>CH4 - Quoting2.jsp</title> </head> <body>
<%! private double toDouble(String value) { return(Double.valueOf(value).doubleValue()); } %>
<% double num1 = toDouble(request.getParameter("num1")); double num2 = toDouble(request.getParameter("num2")); %> 您传入的两个数字为:<%= num1 %> 和 <%= num2 %><br> 两数相加为 <%= (num1+num2) %>
4、include 包含语句
Include.jsp <%@ page contentType="text/html;charset=GB2312" %>
<html> <head> <title>CH4 - Include_Html.jsp</title> </head> <body>
Hello.html: <html><body>
9、使用 GB2312 编码
<%@ page contentType="text/html;charset=GB2312" %>
<html> <head> <title> GB2312.jsp</title> </head> <body>
<h2>使用 GB2312 编码,无法正确显示某些中文字</h2>
JSP 实例学习 100 例
1、 多种字体大小显示
<%@ page language="java" %> <%@ page contentType="text/html; charset=GB2312"%> <html> <head> <title>Hello World</title> <meta http-equiv="Content-Type" content="content=text/html; charset=gb2312"> </head> <body bgcolor="#FFFFFF"> <center> <font size= 5 color=blue>多种字体大小显示</font> <center> <br> <hr> <br> <div align="center"> <% //控制文字大小的循环语句 for( int i=1; i<=6; i++ ) out.println( "<h" + i + ">Hello World!</h" + i + ">" ); %> </div> </body> </html>
<h2>include 命令</h2> <%@ include file="Hello.html" %> <% out.println("欢迎大家进入 JSP 的世界"); %> </body> </html>
JSP 2.0 Tech Reference<br>
</html></body>
5、建立错误处理页面的范例程序
ErrorPage.jsp <%@ page contentType="text/html;charset=GB2312" errorPage="Error.jsp" %>
<html> <head> <title>CH4 - ErrorPage.jsp</title> </head> <body>
<h2>errorPage 的范例程序</h2>
8、设置页面属性
<%@ page contentType="text/html; charset=GB2312" %> <%@ page language="java" %> <!-- 设置页面属性 --> <%@ page info="这就是我们预设的网页属性, 这里我们可以
学习到 page 属性的设置与使用" %>
<>JSP 将会被转译为 Servlet</h2>
相关主题