1、2本次实验分为3个任务:根据实验任务1任务3要求,编写网页程序,并调试运行。 三、实验内容:任务1 JSP页面的基本结构inputName.jsp!DOCTYPE html PUBLIC -/W3C/DTD HTML 4.01 Transitional/EN http:/www.w3.org/TR/html4/loose.dtdhtmlheadmeta http-equiv=Content-Type content=titleInsert title here/headBODY bgcolor=cyanFONT size=3 请输入姓名:INPUT type=text name=nameBRI
2、NPUT TYPE=submit value=送出 name=submit/FORM/BODY/htmlpeople.jsp charset=ISO-8859-1BODY BGCOLOR=yellowFONT Size=3%! int count; StringBuffer person; public void judge() if(count=0) person=new StringBuffer(); public void addPerson(String p) person.append(p); else person.append(,+p); count+; % String nam
3、e=request.getParameter(); byte bb=name.getBytes(iso-8859-1 name=new String(bb); if(name.length()=0|name.length()10)jsp:forward page=inputName.jsp /% judge(); addPerson(name); 目前共有人浏览了该页面,他们的名字是:%=person%/FONT任务2 JSP指令标记first.jsp% page contentType=text/plainHTMLBODY FONT size=5 color=blue%include fil
4、e=sc/fudanmei.txt/HTMLsecond.jspapplication/vnd.ms-powerpointthird.jspapplication/mswordDOCTYPE htmlFONT size=5 color=redfudanmei.txtIt is not how much we have, but how much we enjoy, that makes happiness.brBe happy for this moment. This moment is your life.Happiness is when what you think, what you
5、 say, and what you do are in harmony.The best way to pay for a lovely moment is to enjoy it.任务3 JSP动作标记One.jspinclude page=sc/head062.txt/BODY bgcolor=green 请输入1至100之间的整数:number% String num=request.getParameter( if(num=null) num=0; try int n=Integer.parseInt(num); if(n=1&nparam name=%=n%/jsp:forward
6、% else if(n50&=100)three.jsp catch(Exception e)error.jspmess%=e.toString()%Two.jspcharset=GB2312HEAD/HEADPFont size=5 color=white This is two.jsp./FontFont size=5 String s=request.getParameter( out.println(传递过来的值是+s);img src=sc/a.jpg width=%=s% height=/imgThree.jspFont size=5 color=red This is three
7、.jsp.sc/b.jpgError.jsp This is error.jsp.传递过来的错误信息sc/c.jpg120head062.txttable cellSpacing=1 cellPadding=60% align=center border=tr valign=bottomtdA href=one.jspfont size=5one.jsp页面/A/tdtwo.jsp页面three.jsp页面/table实验三 JSP内置对象1了解 JSP中 9个内置对象 个内置对象request 、response、 out、session、application、config、pagecon
8、text、page 、exception的基本概念。2理解JSP内置对象的常用方法功能。3掌握 JSP内置对象的应用。二、实验原理:在 JSP页面的转换阶段, JSP引擎在 _jspService()方法中声明并初始化了9个隐含对象,它们主要是为了方便在JSP页面对这些象的访问。隐含对象包括: application、session、 request、response 、out、page 、pageContext 、config、exception。在上述 9个隐含对象中,有下面 4个作用域对象,它们是:application、session、request、pageContext。它们主要用
9、来在不同作域中共享数据。1.request对象: import=java.util.*GBKString path = request.getContextPath();String basePath = request.getScheme() + :/+ request.getServerName() + + request.getServerPort()+ path + /DOCTYPE HTML PUBLIC base href=%=basePath%My JSP index.jsp starting pagebody bgcolor=#FFFFF0form action= method
10、=postinput type=提交/form请求方式:%=request.getMethod()%请求的资源:%=request.getRequestURI()%请求用的协议:%=request.getProtocol()%请求的文件名:%=request.getServletPath()%请求的服务器的IP:%=request.getServerName()%请求服务器的端口:%=request.getServerPort()%客户端IP地址:%=request.getRemoteAddr()%客户端主机名:%=request.getRemoteHost()%表单提交来的值:%=reque
11、st.getParameter()%String str = if (request.getParameter() != null) Enumeration enumt = request.getParameterNames();while (enumt.hasMoreElements() str = enumt.nextElement().toString();out.println(str + +request.getParameter(str)+ /body2.response对象:Index.jspgbk你想重定向去哪个网站?bodyString address = request.getParameter(whereif (address !if (address.equals(sohu)response.sendRedirect(else if (address.equals(avceitmypagemypage.jspbPlease select:/bGETselect name=option value= selectedgo to sohugo to avceitgo to mypage/selectgoMypage.jspBODY bgcolor=greenFONT size=13 Welcome To Mypage!3.session对象:met
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2