上机指导第五章

1.编写一个UserJsp.jsp页面向用户显示姓名,页面使用useBean标准动作。要求同时使用setProperty动作将用户姓名设置为anne。getProperty动作用于获取anne的名字。

package com.ch5.bean;

public class User {

private String userName;

private String address;

private String password;

public String getUserName() {

return userName;

}

public void setUserName(String userName) {

this.userName = userName;

}

public String getAddress() {

return address;

}

public void setAddress(String address) {

this.address = address;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

}

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>

<jsp:useBean id="user" class="com.ch5.bean.User"></jsp:useBean>

<jsp:setProperty property="userName" name="user" value="anne"/>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>My JSP 'index.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" href="styles.css">

-->

</head>

<body>

UserName:<jsp:getProperty name="user" property="userName"/><br>

</body>

</html>

2.创建一个JavaBean,用来接受汽车的颜色,以及表示汽车是否安装了空调的布尔值。如果布尔值为真,则汽车安装了空调;如果布尔值为假,则汽车未安装空调。该JavaBean返回颜色和布尔值(完成JavaBean,创建一个页面显示结果)。

package com.ch5.bean;

public class Car {

String color;

boolean airConditioner;

public String getColor() {

return color;

}

public void setColor(String color) {

this.color = color;

}

public boolean isAirConditioner() {

return airConditioner;

}

public void setAirConditioner(boolean airConditioner) {

this.airConditioner = airConditioner;

}

}

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<base href="<%=basePath%>">

<title>My JSP 'CarJsp.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" href="styles.css">

-->

</head>

<body>

<form action="CarResult.jsp" method="post">

颜色:<input name="color" type="text"/><br/>

是否安装空调:<input name="airConditioner" type="checkbox"/><br/>

<input value="submit" type="submit"/>

</form>

</body>

</html>

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

request.setCharacterEncoding("UTF-8");

%>

<jsp:useBean id="car" class="com.ch5.bean.Car"></jsp:useBean>

<jsp:setProperty property="*" name="car"/>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<base href="<%=basePath%>">

<title>My JSP 'CarJsp.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" href="styles.css">

-->

</head>

<body>

<form action="CarResult.jsp">

颜色:<jsp:getProperty property="color" name="car"/><br/>

是否安装空调::<jsp:getProperty property="airConditioner" name="car"/>

</form>

</body>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值