<%-- 网站: <a href="http://www.crazyit.org">疯狂Java联盟</a> author yeeku.H.lee kongyeeku@163.com version 1.0 Copyright (C), 2001-2016, yeeku.H.Lee This program is protected by copyright laws. Program Name: Date: --%> <%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> Java Bean测试 </title> <meta name="website" content="http://www.crazyit.org" /> </head> <body> <!-- 创建lee.Person的实例,该实例的实例名为p1 --> <jsp:useBean id="p1" class="lee.Person" scope="page"/> <!-- 设置p1的name属性值 --> <jsp:setProperty name="p1" property="name" value="crazyit.org"/> <!-- 设置p1的age属性值 --> <jsp:setProperty name="p1" property="age" value="23"/> <!-- 输出p1的name属性值 --> <jsp:getProperty name="p1" property="name"/><br/> <!-- 输出p1的age属性值 --> <jsp:getProperty name="p1" property="age"/> </body> </html>
<%-- 网站: <a href="http://www.crazyit.org">疯狂Java联盟</a> author yeeku.H.lee kongyeeku@163.com version 1.0 Copyright (C), 2001-2016, yeeku.H.Lee This program is protected by copyright laws. Program Name: Date: --%> <%@ page contentType="text/html; charset=GBK" language="java" isErrorPage="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> 错误提示页面 </title> <meta name="website" content="http://www.crazyit.org" /> </head> <body> <!-- 提醒客户端系统出现异常 --> 系统出现异常<br/> </body> </html>
<%-- 网站: <a href="http://www.crazyit.org">疯狂Java联盟</a> author yeeku.H.lee kongyeeku@163.com version 1.0 Copyright (C), 2001-2016, yeeku.H.Lee This program is protected by copyright laws. Program Name: Date: --%> <%@ page contentType="text/html; charset=GBK" language="java" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> new document </title> <meta name="website" content="http://www.crazyit.org" /> </head> <body> <% // 下面代码将出现运行时异常 int a = 6; int b = 0; int c = a / b; %> </body> </html>
<%-- 网站: <a href="http://www.crazyit.org">疯狂Java联盟</a> author yeeku.H.lee kongyeeku@163.com version 1.0 Copyright (C), 2001-2016, yeeku.H.Lee This program is protected by copyright laws. Program Name: Date: --%> <%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> 提交 </title> <meta name="website" content="http://www.crazyit.org" /> </head> <body> <!-- 表单提交页面 --> <form id="login" method="post" action="jsp-forward.jsp"> <input type="text" name="username"> <input type="submit" value="login"> </form> </body> </html>
<%-- 网站: <a href="http://www.crazyit.org">疯狂Java联盟</a> author yeeku.H.lee kongyeeku@163.com version 1.0 Copyright (C), 2001-2016, yeeku.H.Lee This program is protected by copyright laws. Program Name: Date: --%> <%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>forward结果页</title> <meta name="website" content="http://www.crazyit.org" /> </head> <body> <!-- 使用request内置对象获取age参数的值 --> <%=request.getParameter("age")%> <!-- 输出username请求参数的值 --> <%=request.getParameter("username")%> </body> </html>
<%-- 网站: <a href="http://www.crazyit.org">疯狂Java联盟</a> author yeeku.H.lee kongyeeku@163.com version 1.0 Copyright (C), 2001-2016, yeeku.H.Lee This program is protected by copyright laws. Program Name: Date: --%> <%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> forward的原始页 </title> <meta name="website" content="http://www.crazyit.org" /> </head> <body> <h3>forward的原始页</h3> <jsp:forward page="forward-result.jsp"> <jsp:param name="age" value="29"/> </jsp:forward> </body> </html>
<%-- 网站: <a href="http://www.crazyit.org">疯狂Java联盟</a> author yeeku.H.lee kongyeeku@163.com version 1.0 Copyright (C), 2001-2016, yeeku.H.Lee This program is protected by copyright laws. Program Name: Date: --%> <%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> jsp-include测试 </title> <meta name="website" content="http://www.crazyit.org" /> </head> <body> <!-- 使用动态include指令导入页面 --> <jsp:include page="scriptlet.jsp" /> </body> </html>
<%-- 网站: <a href="http://www.crazyit.org">疯狂Java联盟</a> author yeeku.H.lee kongyeeku@163.com version 1.0 Copyright (C), 2001-2016, yeeku.H.Lee This program is protected by copyright laws. Program Name: Date: --%> <%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> jsp-include测试 </title> <meta name="website" content="http://www.crazyit.org" /> </head> <body> <jsp:include page="forward-result.jsp" > <jsp:param name="age" value="32"/> </jsp:include> </body> </html>
<%-- 网站: <a href="http://www.crazyit.org">疯狂Java联盟</a> author yeeku.H.lee kongyeeku@163.com version 1.0 Copyright (C), 2001-2016, yeeku.H.Lee This program is protected by copyright laws. Program Name: Date: --%> <%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %> <!-- 指定info信息 --> <%@ page info="this is a jsp"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> 测试page指令的info属性 </title> <meta name="website" content="http://www.crazyit.org" /> </head> <body> <!-- 输出info信息 --> <%=getServletInfo()%> </body> </html>
<%-- 网站: <a href="http://www.crazyit.org">疯狂Java联盟</a> author yeeku.H.lee kongyeeku@163.com version 1.0 Copyright (C), 2001-2016, yeeku.H.Lee This program is protected by copyright laws. Program Name: Date: --%> <%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> 小脚本测试 </title> <meta name="website" content="http://www.crazyit.org" /> </head> <body> <table bgcolor="#9999dd" border="1" width="300px"> <!-- Java脚本,这些脚本会对HTML的标签产生作用 --> <% for(int i = 0 ; i < 10 ; i++) { %> <!-- 上面的循环将控制<tr>标签循环 --> <tr> <td>循环值:</td> <td><%=i%></td> </tr> <% } %> <table> </body> </html>
<%-- 网站: <a href="http://www.crazyit.org">疯狂Java联盟</a> author yeeku.H.lee kongyeeku@163.com version 1.0 Copyright (C), 2001-2016, yeeku.H.Lee This program is protected by copyright laws. Program Name: Date: --%> <%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> 静态include测试 </title> <meta name="website" content="http://www.crazyit.org" /> </head> <body> <!-- 使用include编译指定导入页面 --> <%@include file="scriptlet.jsp"%> </body> </html>
<?xml version="1.0" encoding="GBK"?> <!-- 定义生成文件的project根元素,默认的target为空 --> <project name="web" basedir="." default=""> <!-- 定义三个简单属性 --> <property name="src" value="src"/> <property name="classes" value="classes"/> <!-- 定义一组文件和目录集 --> <path id="classpath"> <fileset dir="lib"> <include name="*.jar"/> </fileset> <pathelement path="${classes}"/> </path> <!-- 定义compile target,用于编译Java源文件 --> <target name="compile" description="编译Java源文件"> <!-- 先删除classes属性所代表的文件夹 --> <delete dir="${classes}"/> <!-- 创建classes属性所代表的文件夹 --> <mkdir dir="${classes}"/> <!-- 编译Java文件,编译后的class文件放到classes属性所代表的文件夹内 --> <javac destdir="${classes}" debug="true" includeantruntime="yes" deprecation="false" optimize="false" failonerror="true"> <!-- 指定需要编译的Java文件所在的位置 --> <src path="${src}"/> <!-- 指定编译Java文件所需要第三方类库所在的位置 --> <classpath refid="classpath"/> </javac> </target> </project>
<?xml version="1.0" encoding="GBK"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <servlet> <servlet-name>aa</servlet-name> <servlet-class>lee.HelloServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>aa</servlet-name> <url-pattern>/aa</url-pattern> </servlet-mapping> </web-app>
package lee; /** * Description: * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a> * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee * <br/>This program is protected by copyright laws. * <br/>Program Name: * <br/>Date: * @author Yeeku.H.Lee kongyeeku@163.com * @version 1.0 */ public class Person { private String name; private int age; // 无参数的构造器 public Person() { } // 初始化全部成员变量的构造器 public Person(String name , int age) { this.name = name; this.age = age; } // name的setter和getter方法 public void setName(String name) { this.name = name; } public String getName() { return this.name; } // age的setter和getter方法 public void setAge(int age) { this.age = age; } public int getAge() { return this.age; } }