JSP——页面的基本结构

实验要求:

编写两个JSP页面,名字分别为inputName.jsp和people.jsp

inputName.jsp的具体要求:

该页面有一个表单,用户通过该表单输入自己的姓名并提交给people.jsp页面

people.jsp的具体要求:

(1)JSP页面有名字为personList,类型是StringBuffer以及名字是count,类型为int的成员变量。

(2)JSP页面有public void judge()方法,该方法负责创建personList对象,当count的值是0时,judge()方法创建personList对象

 

inputName.jsp代码文件

<%@ page contentType="text/html;charset=utf-8" %>

<html>

<body>

<form action="people.jsp" method=get name=form>

请输入姓名:<input type="text"name ="name"><br>

<input type="submit" value="送出" name=submit>

</form>

</body>

</html>

 

 

people.jsp代码文件

<%@ page contentType="text/html;charset=utf-8" %>

<html>

<body>

<%!

int count;

StringBuffer personList;

public void judge()

{

if(count==0)

{

personList=new StringBuffer();

}

}

public void addPerson(String p)

{

if(count==0)

personList.append(p);

else

personList.append(','+p);

count++;

}

 %>

 <%

  String name=request.getParameter("name");

  if(name.length()==0||name.length()>10)

  {

  %>

   <jsp:forward page="inputName.jsp"></jsp:forward>

 <%

  }

  judge();

  addPerson(name);

  %>

    <br>目前共有<%=count %>人浏览了该页面,他们的名字是:

    <br><%=personList %>

</body>

</html>

 

 

浏览器显示结果:

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值