J2EE电子商务平台课内实验报告书文档格式.docx
《J2EE电子商务平台课内实验报告书文档格式.docx》由会员分享,可在线阅读,更多相关《J2EE电子商务平台课内实验报告书文档格式.docx(71页珍藏版)》请在冰点文库上搜索。
2.本次实验分为3个任务:
根据实验任务1~任务3要求,编写网页程序,并调试运行。
三、实验内容:
任务1JSP页面的基本结构
inputName.jsp
<
%@pagelanguage="
java"
contentType="
text/html;
charset=GB2312"
pageEncoding="
UTF-8"
%>
!
DOCTYPEhtmlPUBLIC"
-//W3C//DTDHTML4.01Transitional//EN"
"
http:
//www.w3.org/TR/html4/loose.dtd"
>
html>
head>
metahttp-equiv="
Content-Type"
content="
title>
Inserttitlehere<
/title>
/head>
BODYbgcolor=cyan>
FONTsize=3>
<
FORMaction="
people.jsp"
method=getname=form>
请输入姓名:
INPUTtype="
text"
name="
name"
BR>
INPUTTYPE="
submit"
value="
送出"
name=submit>
/FORM>
/BODY>
/html>
people.jsp
charset=ISO-8859-1"
BODYBGCOLOR=yellow>
FONTSize=3>
%!
intcount;
StringBufferperson;
publicvoidjudge()
{
if(count==0)
person=newStringBuffer();
}
publicvoidaddPerson(Stringp)
{
person.append(p);
}
else
person.append("
"
+p);
count++;
%>
%
Stringname=request.getParameter("
);
bytebb[]=name.getBytes("
iso-8859-1"
name=newString(bb);
if(name.length()==0||name.length()>
10)
jsp:
forwardpage="
inputName.jsp"
/>
%}
judge();
addPerson(name);
目前共有<
%=count%>
人浏览了该页面,他们的名字是:
%=person%>
/FONT>
任务2JSP指令标记
first.jsp
%@pagecontentType="
text/plain"
HTML>
BODY>
FONTsize=5color=blue>
%@includefile="
sc/fudanmei.txt"
/HTML>
second.jsp
application/vnd.ms-powerpoint"
third.jsp
application/msword"
DOCTYPEhtml>
FONTsize=5color=red>
fudanmei.txt
Itisnothowmuchwehave,buthowmuchweenjoy,thatmakeshappiness.
br>
Behappyforthismoment.Thismomentisyourlife.
Happinessiswhenwhatyouthink,whatyousay,andwhatyoudoareinharmony.
Thebestwaytopayforalovelymomentistoenjoyit.
任务3JSP动作标记
One.jsp
includepage="
sc/head062.txt"
/>
BODYbgcolor=green>
"
请输入1至100之间的整数:
number"
%
Stringnum=request.getParameter("
if(num==null)
{num="
0"
;
try
intn=Integer.parseInt(num);
if(n>
=1&
&
n<
=50)
two.jsp"
>
paramname="
%=n%>
/jsp:
forward>
%}
elseif(n>
50&
=100)
three.jsp"
catch(Exceptione)
error.jsp"
mess"
%=e.toString()%>
Two.jsp
charset=GB2312"
HEAD>
/HEAD>
P>
Fontsize=5color=white>
Thisistwo.jsp.
/Font>
Fontsize=5>
Strings=request.getParameter("
out.println("
传递过来的值是"
+s);
imgsrc="
sc/a.jpg"
width="
%=s%>
height="
/img>
Three.jsp
Fontsize=5color=red>
Thisisthree.jsp.
sc/b.jpg"
Error.jsp
Thisiserror.jsp.
传递过来的错误信息"
sc/c.jpg"
120"
head062.txt
tablecellSpacing="
1"
cellPadding="
60%"
align="
center"
border="
trvalign="
bottom"
td>
Ahref="
one.jsp"
fontsize=5>
one.jsp页面<
/font>
/A>
/td>
two.jsp页面<
three.jsp页面<
/tr>
/table>
实验三JSP内置对象
1.了解JSP中9个内置对象个内置对象request、response、out、session、application、config、pagecontext、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。
它们主要用来在不同作域中共享数据。
1.request对象:
import="
java.util.*"
GBK"
Stringpath=request.getContextPath();
StringbasePath=request.getScheme()+"
:
//"
+request.getServerName()+"
+request.getServerPort()
+path+"
/"
DOCTYPEHTMLPUBLIC"
basehref="
%=basePath%>
MyJSP'
index.jsp'
startingpage<
pragma"
no-cache"
cache-control"
expires"
keywords"
keyword1,keyword2,keyword3"
description"
Thisismypage"
--
linkrel="
stylesheet"
type="
text/css"
href="
styles.css"
-->
bodybgcolor="
#FFFFF0"
formaction="
method="
post"
inputtype="
提交"
/form>
请求方式:
%=request.getMethod()%>
请求的资源:
%=request.getRequestURI()%>
请求用的协议:
%=request.getProtocol()%>
请求的文件名:
%=request.getServletPath()%>
请求的服务器的IP:
%=request.getServerName()%>
请求服务器的端口:
%=request.getServerPort()%>
客户端IP地址:
%=request.getRemoteAddr()%>
客户端主机名:
%=request.getRemoteHost()%>
表单提交来的值:
%=request.getParameter("
)%>
Stringstr="
if(request.getParameter("
)!
=null){
Enumerationenumt=request.getParameterNames();
while(enumt.hasMoreElements()){
str=enumt.nextElement().toString();
out.println(str+"
+request.getParameter(str)+"
}
/body>
2.response对象:
Index.jsp
gbk"
你想重定向去哪个网站?
body>
Stringaddress=request.getParameter("
where"
if(address!
if(address.equals("
sohu"
))
response.sendRedirect("
elseif(address.equals("
avceit"
mypage"
mypage.jsp"
b>
Pleaseselect:
/b>
GET"
selectname="
optionvalue="
selected>
gotosohu
gotoavceit
gotomypage
/select>
go"
Mypage.jsp
BODYbgcolor="
green"
FONTsize=13>
WelcomeToMypage!
3.session对象:
met