3. 简述JSP内置对象、作用及有效范围。
三、程序填空
1.下面是用户注册程序,login.jsp提交管理员用户名和密码,reg.jsp接收并处理信息。 login.jsp
<%page contentType=” ”%>
reg.jsp
<%page contentType=” ”%>
<% String name=request.getParameter(“ ”); String pass=request.getParameter(“pass”); if( )
name=””;
name=new String( ); if( ) pass=””;
if(name.equals(\
{ out.print (\欢迎你,管理员\注册成功\%>
2.在服务器端将文字“你们好! Nice to meet you!”写入C:\\hello.txt文件,然后读取该文件显示给给客户。
<%@page contentType=\<%@page import=\ \
<% File f=new (\ try{
FileOutputStream outfile=new FileOutputStream( ); BufferedOutputStream BufferedOutputStream(outfile);
byte b[]=\你们好!
Nice to meet you!\ bufferout.write( ); bufferout. ; bufferout.close();
bufferout=new
outfile.close();
FileInputStream in=new FileInputStream(f);
BufferedInputStream bufferin=new BufferedInputStream(in); byte c[]=new byte[90]; int n=0;
while((n= )!=-1){ String temp=new String(c,0,n); out.print( ); }
.close(); .close();
}catch(IOException e){ } %>
四、阅读下面的程序,写出include.jsp的运行结果。 include.jsp代码:
<%@ page contentType=\
<%@ include file=\
<%@ include file=\<%@ include file=\ abc.html代码: mytxt.txt代码: 你好,这是jsp程序。 mycode.cod代码: <%
String s1=\执行代码在这里显示\out.print(\%>
参考答案
一. 选择题
二. 问答题
1. 从当前页面跳转到test.jsp页面有几种方法?如何实现? jsp:forward操作指令用于把当前的JSP页面转发到另一个页面上。
基本语法为:
“ 2. application对象和session对象有什么联系和区别? 站点所有的用户公用一个application对象,当站点服务器开启的时候,application就被创建,直到网站关闭。 可以使用Session 对象存储用户登录网站时候的信息。当用户在页面之间跳转时,存储在Session对象中的变量不会被清除 联系是:数据都存储在服务器端,而且都可以保留一段时间。 区别是:每个用户有一个session,但是application是共有的。 3. 简述JSP内置对象、作用及有效范围。 1) application 有效范围:application 作用:用于保存所有应用程序中的公有数据,服务器启动并且自动创建application对像后,只要没关闭服务器,application对象将一直存在; 2) Config 有效范围:page 作用:将初始化数据传递给一个JSP页面; 3) exception 有效范围:page 作用:该对象含有只能由指定的JSP“错误处理页面”访问的异常数