太原理工web实验报告Word格式.docx
《太原理工web实验报告Word格式.docx》由会员分享,可在线阅读,更多相关《太原理工web实验报告Word格式.docx(31页珍藏版)》请在冰豆网上搜索。
<
head>
title>
Example<
/title>
/head>
bodybgcolor="
#00DDFF"
>
h1>
B>
I>
FONTCOLOR="
#FF00FF"
MARQUEEBGCOLOR="
#FFFF00"
direction=leftbehavior=alternate>
welcometoyou<
/MARQUEE>
/FONT>
/I>
/B>
/h1>
hr>
h2align=center>
#0000FF"
AsimpleHTMLdocument<
/h2>
EM>
WelcometotheworldofHTML<
/EM>
p>
ThisisasimpleHTMLdocument.ItistogiveyouanoutlineofhowtowriteHTMLfile
andhowthe<
b>
markuptags<
/b>
workinthe<
HTML<
file<
/p>
Followingisathreechapters
ul>
li>
Thisisthechapterone<
/li>
AHREF="
#item"
Thisisthechaptertwo<
/A>
Thisisthechapterthree<
/ul>
ANAME="
item"
Followingisitemsofthechaptertwo<
tableborder=2bgcolor=graywidth="
40%"
tr>
th>
item<
/th>
content<
/tr>
td>
item1<
/td>
font<
item2<
table<
item3<
form<
/table>
1<
2<
3<
4<
5<
6<
7<
FONTCOLOR=BLUESIZE=4>
Endoftheexampledocument
/body>
/html>
2.编写一个能输出如图所示界面的HTML文件。
四、实验结果
1.
2.程序清单:
表单范例<
body>
tablealign="
center"
caption>
h2>
请留下个人资料<
hrsize="
1"
width="
170"
color="
black"
/caption>
formname="
form"
tdalign="
right"
inputtype="
text"
name="
姓名"
E-mail:
邮箱"
电话:
电话"
性别:
radio"
性别"
checked>
女
男<
年龄:
select>
optionselected>
20以下
option>
40以下
60以下
60以上
/select>
留言板:
textareaname="
留言板"
rows="
5"
cols="
40"
/textarea>
br>
您的爱好:
checkbox"
运动"
运动<
阅读"
阅读<
听音乐"
听音乐<
旅游"
旅游
colspan="
2"
submit"
提交"
value="
&
nbsp&
nbsp<
reset"
重写"
全部重写"
/form>
五、讨论、心得
通过此次实验,让我收获许多,主要收获如下:
1.能熟练地掌握基本的HTML语言标记,懂得每一个标记所代表的意思。
2.进一步熟悉了表单的制作过程以及表单中各标记的灵活应用。
网页程序设计JavaScript
一、实验目的
3.掌握JavaScript技术,基本掌握JavaScript的开发技巧。
4.利用文本编辑器建立JavaScript脚本语言进行简单编程。
二、实验要求
3.根据以下实验内容书写实验准备报告。
4.独立完成实验。
三、实验内容
1、显示一个动态的时钟
在文本编辑器“记事本”中输入如下代码程序,请仔细阅读下列语句,理解每条语句的作用。
scriptlanguage="
javascript"
vartimer=null;
functionstop()
{
clearTimeout(timer);
}
functionstart()
{
vartime=newDate();
varhours=time.getHours();
varminutes=time.getMinutes();
minutes=((minutes<
10)?
"
0"
:
)+minutes;
varseconds=time.getSeconds();
seconds=((seconds<
)+seconds;
varclock=hours+"
+minutes+"
+seconds;
document.forms[0].display.value=clock;
timer=setTimeout("
start()"
1000);
/script>
bodyonload="
onunload="
stop()"
form>
现在是北京时间:
inputtype="
name="
display"
size="
20"
/from>
分析上述代码的作用,然后用浏览器运行文件,验证自己的判断是否正确。
2、事件驱动和事件处理
functionmyfunction()
alert("
HELLO"
);
button"
onclick="
myfunction()"
Callfunction"
Bypressingthebutton,afuntionwillbecalled.Thefunctionwillalertamessage.<
3.JavaScript表单校验
编写程序register.htm,做一个如下图所示的用户注册界面,要求对用户填写的部分进行合法性验证。
四、实验结果
1、
2、
3.程序清单:
用户登录<
script>
functionmyfunction(){
if(form.username.value=="
)
{
用户名不能为空,请输入用户名!
form.username.focus();
returnfalse;
}
if(form.password.value=="
密码不能为空,请输入密码"
form.password.focus();
用户登录<
onsubmit="
returnmyfunction()"
method="
post"
action="
sy2-3
(2).html"
请输入用户名:
username"
请输入密码:
password"
五、讨论、心得
1.学会使用JavaScript脚本语言进行简单的编程。
2.基本掌握了JavaScript的开发技巧,理解了事件驱动与事件处理还有事件之间的区别。
Request与Response对象的应用
一.实验目的
1.掌握JSP的Request与Response隐式对象的用法,基本掌握JSP的开发技巧。
2.在JDK和Eclipse环境下,完成下列实验。
二.实验内容
编写程序实现一个单选小测试。
在test.jsp页面显示问题,并将答案提交至answer.jsp进行判断,如果回答正确,则将页面转至yes.jsp;
否则,转至no.jsp。
三.实验过程中遇到的问题及解决方法
软件在配置过程中遇到一些问题,和tomcat连接时由于使用的全部为英文软件,操作有些困难。
在进行编写程序的时候不会页面跳转,后使用response.sendRedirect()命令来进行页面的跳转,并且产生不同的结果。
四.实验结论和感想
在不断地摸索中掌握JSP的Request与Response隐式对象的用法,以及在jsp环境下如何配置,编译,编程是一个锻炼人耐心的工作,遇到的重重问题只有在不断尝试和克服下,才能获取成功。
五.实验程序
Test.jsp
%@pagelanguage="
java"
import="
java.util.*"
pageEncoding="
utf-8"
%>
body>
<
北京奥运会开幕日期是:
formaction="
ansewr.jsp"
method=postname=form1>
inputtype=radioname="
date"
checkedvalue="
6"
8月6日
8"
8月8日
9"
8月9日
10"
8月10日<
inputtype=submitvalue=提交答案>
answer.jsp
%
Stringmydate;
mydate=request.getParameter("
if(mydate.equals("
))
response.sendRedirect("
yes.jsp"
elseresponse.sendRedirect("
no.jsp"
%>
yes.jsp<
bodybackground="
D:
\MyEclipseXX\SSS\WebRoot\1.jpg"
恭喜您答对了!
no.jsp
很抱歉,您答错了!
Application对象Session对象
5.掌握JSP的Application对象Session对象的用法,基本掌握JSP的开发技巧。
6.在JDK和Eclipse环境下,完成下列实验。
5.独立完成实验。
6.书写实验报告书。
1.请仔细阅读下列程序语句,理解每条语句的作用。
%@pagecontentType="
text/html;
charset=gb2312"
网页计数器<
%if(application.getAttribute("
counter"
)==null)
application.setAttribute("
"
else{
Stringstrnum=null;
strnum=application.getAttribute("
).toString();
inticount=0;
icount=Integer.valueOf(strnum).intValue();
icount++;
Integer.toString(icount));
}
您是第<
%=application.getAttribute("
)%>
位访客!
2.上述计数器当进行刷新时也会自动加1,是编写程序count.jsp,实现防刷新文本计数器。
3.编写程序register.htm和register.jsp,做一个用户注册的界面,要求对用户填写的部分进行合法性检验,然后提交到register.jsp进行注册检验,若用户名为user开头的,就提示“该用户名已被注册”,若用户名为admin,就提示“欢迎您,管理员”,否则,就显示“注册成功”。
4.1中的计数器不能防止刷新,当进行刷新时也会自动加1。
5.源程序清单:
if(session.isNew()){
程序清单:
Register.htm:
用户注册<
h2align="
register.jsp"
>
table>
用户名:
user"
id="
/>
密&
nbsp码:
注册"
tdalgin="
重置"
Register.jsp:
gb2312"
Stringpath=request.getContextPath();
StringbasePath=request.getScheme()+"
//"
+request.getServerName()+"
+request.getServerPort()+path+"
/"
;
!
DOCTYPEHTMLPUBLIC"
-//W3C//DTDHTML4.01Transitional//EN"
basehref="
%=basePath%>
MyJSP'
register.jsp'
startingpage<
metahttp-equiv="
pragma"
content="
no-cache"
cache-control"
expires"
keywords"
keyword1,keyword2,keyword3"
description"
Thisismypage"
--
linkrel="
stylesheet"
type="
text/css"
href="
styles.css"
-->
%Stringa;
a=request.getParameter("
if(a.indexOf("
)==0){
out.println("
该用户名已被注册!
elseif(a.toString().matches("