资源描述
Web编程技术模拟试卷(B卷)
一、 填空题 20分 (20*1)
1. 请写出常用的Web服务器 :IIS、Apache、Tomcat.
2. 请写出常用的常用的Web编辑工具:Dreamweaver、Editplue、Eclipse
3. JDBC 、JSP、 DAO英文全称分别是:JDBC:Java Data Base Connectiving
JSP:Java Server Page DAO:Data Access Object
4. JSP的内置对象有out、request、response、session、application
5. 连接数据库的四要素:数据库驱动、数据库的URL、数据库的用户名、数据库的密码
二、 选择题 15分 (15*1)
1. 下面那个控件的属性设立成相同可以达成各个控件共同一组的效果(B)
A id B name C type D value
2. 下面哪一个JSP的注释,客户端是可见的(A)
A<!--comment-->B// C<%--comment--> D/*....*/
3. <jsp:param />不与下列哪些操作指令配合使用(D)
A<jsp:include> B <jsp:forward> C<jsp:plugin> D<jsp:setProperty />
4. 下列哪一个不是JDBC的接口(D)
A DriverManager B Connection C Statement D Preparement
5.jsp执行过程:Jsp-》java-》class-》网页f分别是以下哪个顺序过程?(A)
A.翻译-》编译-》执行B.翻译-》执行-》编译
C.编译-》翻译-》执行 D.执行-》编译-》翻译
6. 如下选项有哪一个是jsp表达式?A
A. <%= 9i %> B.<% int i %> C.x=3y+1 D.<% x=3y+1 %>
7. Javascript 连接js文献方法 <script languae=“javascript”src=“__A___”></script>
A a.js B.b.java C css.cs D web.xml
8. 下面哪一个不是单标签?(D)
A. <br> B.<hr> C.<img> D.<body>
9. 当点击提交后跳转 客户端通过(A)访问服务器
A IE B 我的电脑 C网上邻居 D回收站
10. 关闭sql数据库的顺序是(A)
A先关闭结果集再关闭操作最后关闭连接
B先关闭连接再关闭操作最后关闭结果集
C先关闭操作再关闭结果集最后关闭连接
D先关闭结果集再关闭连接最后关闭操作
11. 下列说法对的的是(A)
A. jsp不一定是jsp开发的
B. Jsp一定是jsp开发的
C. Jsp编译后生成java后缀
D. Jsp运营后生成java后缀
12. 第三方jar文献保存在哪一个目录下?()
A WEB ROOT B WEB ROOT/WEB-INF
CWEB ROOT/WEB-INF/lib D WEB ROOT/WEB-INF/classes
13. <input type=”password”>123456</input>在页面中显示的效果是(B)
A 123456 B******C.password:123456 D123456******
14.可以运用request对象的哪个方法获取客户端的表单信息?A
A)response.getParameter() B)response.outParameter()
C)response.writeParameter() D)response.handlerParameter()
15.<select>用于在表单中插入一个下拉菜单,它需与哪个标记配合使用?D
A)<list> B)<item> C)<dot> D)<option>
三、单句代码解释题20分(10*2)
1.<a href=“” target=“_blank”><img src=”jiageng.jpg”/></a>
点击嘉庚图片超连接到集美大学网页
2. index.jsp:<form name='myform' method="POST" action="a1.htm" onsubmit="return check()"> 表单以post的方式提交到a1.html提交的时候并调用javascript的check函数检查
3. setTimeOut(“a()”,5000) alert(“xxxx”)
定期 onload 网页加载延时5000毫秒调用a函数执行a方法并弹出警告框提醒
4. var time = new Date(); 获取当前日期
5. <body onload='document.myform.name.focus()'> 页面加载时使光标停留在myform表单的name控件位置聚焦
6. response.setHeader("refresh","2");
out.println(new Date());//每隔2秒自动刷新显示时间
7. <input type=”hidden”>//隐藏域 看不见页面上自身用户不能在其中输入用来预设某些要传送的信息。
8. <% request.setCharacterEncoding("gb2312"); %>//设立编码防止乱码
9. request.getParameter(); //传递参数 返回值类型为String
request.getParameterValues(); //获得参数所包含的值 一组多个值
10.session.setAttribute(); //设立属性 防盗链 保存用户名
session.getAttribute(); //取得属性
session.isNew(); //判断是否是一个新的用户
session.invalidate();//使session失效 注销退出
application.getAttribute(); //返回对象 获取
application.setAttribute();//添加对象 设立
四、简答题 10分(5*2)
1.简朴介绍下JSP的开发环境如何搭建以及JSP程序如何运营?
1.安装JDK 添加环境变量2.安装Tomcat在IE中输入 :8080 或 http://本机ip:8080 或 http://localhost:8080)。检查是否启动成功出现猫,若此时浏览器中显示Tomcat的欢迎和管理画面,即表达服务器安装和启动成功。3.安装SQL Server2023 4.安装MyEclipse7.5 关于Tomcat服务器虚拟目录的配置打开Tomcat的安装目录,进入conf/server.xml,在</host>上方加入<Context path="/虚拟目录名" docBase="虚拟目录途径"/>
2.<jsp:include />与<%@ include %>有什么区别?(B卷)
<%@ include %>包含静态的内容 先包含后解决 <jsp:include /> 动态包含 先解决后包含
3. <jsp:forward />与response.sendRedirect()有什么区别?(B卷)
<jsp:forward /> URL不变,服务端跳转 无条件跳转 之后代码不再执行释放资源传递参数response.sendRedirect() URL地址改变,客户端跳转 有条件跳转 不能保存request的属性 URL重写传递参数
4.Page、request、session与application的区别是什么?生成期、作用范围又有何不同?
①在一个页面范围内:page
②在一次服务器请求范围内:request
③在一次会话范围内:session
④在一个应用服务器范围内:application
5. DAO数据访问接口的用途是什么?
前台显示与后台逻辑操作分离 ,JSP页面的功能就是将DAO返回的结果进行输出。
6.Servlet的开发环节 servlet的核心代码写在哪?在哪里注册?
一般情况下,重要用到doGet和doPost方法。 web.xml注册
7.在这学期开发过程碰到什么问题,你又是如何解决的?A卷考过
五、 程序解释题 10分(5*2)
1. 分析程序运营结果
原网页a1.jsp:
程序一:system.out.println(“aaa”);
<jsp:forward page=”a2.jsp”/>
System.out.println(“bbb”);
运营结果:aaa URL地址:a1.jsp 属于服务端跳转
程序二:
system.out.println(“aaa”);
response.sendRedirect(“a2.jsp”);
System.out.println(“bbb”);
运营结果:aaa bbb URL地址:a2.jsp 属于客户端跳转
2. IncludeDemo.jsp:
<%
int j= 100 ;
%>
<h1>includeDemo.jsp中的:<%=j%></h1>
<%@ include file="include.jsp"%>
Include.jsp:
<%
int i = 10 ;
%>
<h1>include.jsp:<%=i%></h1>
运营结果:
includeDemo.jsp中的:100
include.jsp:10
3.scope四种范围:
page,只在当前页有效,合用于操作数据库 调用两次 结果显示
request,属性只保存在一次服务器跳转中,使用<jsp:forward>才可 调用1次刷新递增
session,属性保存在一次会话中,合用于开发购物车等 无论怎么刷新也不会重新声明
数字递增
application,属性公有,此对象在整个服务器只实例化一次 只创建一次
六、程序改写题5分(5*1)
1.B卷中代码改写 效率提高题目给代码 表单提交改写成Java Bean
源代码:
<%@ page contentType="text/html" pageEncoding="GBK"%>
<html>
<head><title></title></head>
<body>
<% request.setCharacterEncoding("GBK") ; %>
<jsp:useBean id="simple" scope="page" class="jmu.SimpleBean"/>
<%
simple.setName(request.getParameter("name"));
simple.setAge(Integer.parseInt(request.getParameter("age")));
%>
<h3>姓名:<%=simple.getName()%></h3>
<h3>年龄:<%=simple.getAge()%></h3>
</body>
</html>
改写
<%@ page contentType="text/html" pageEncoding="GBK"%>
<html>
<head><title></title></head>
<body>
<% request.setCharacterEncoding("GBK") ; %>
<jsp:useBean id="simple" scope="page" class="jmu.SimpleBean"/>
<jsp:setProperty name="simple" property="*"/>
<jsp:setProperty name="simple" property="name" param="age"/>
<jsp:setProperty name="simple" property="age" param="name"/>
<h3>姓名:<%=simple.getName()%></h3>
<h3>年龄:<%=simple.getAge()%></h3>
</body>
</html>
七、设计题 10分(10*1)
1.编写一个可以打印出九九乘法表的JSP网页,规定对齐和一定的修饰(B卷规定用表达式)
<table border=2 >
<%for(int i=1;i<=9;i++){%>
<tr>
<%for(int j=1;j<=i;j++){%>
<td><%=j%>*<%=i%>=<%=i*j%> </td><%}%>
</tr><%}%>
</table>
A卷考过的
四部曲
<%
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance(); //加载驱动程序
String url="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=testdb"; //定义数据库的地址,tempdb为所要访问的数据库名称,127.0.0.1:1433是ip地址和端口
String user="sa"; //数据库的用户名
String password="123456"; //数据库的密码
Connection conn= DriverManager.getConnection(url,user,password); //连接数据库
Statement stmt=conn.createStatement(); //创建Statmen语句总管
String sql="select * from dbo.person"; //构造所要执行的SQL语句,dbo.person是tempdb数据库中的一个表
ResultSet rs=stmt.executeQuery(sql); //执行sql语句并返回结果给所定义的结果集
%>
第一个字段 第二个字段<br>
<%
//下面通过循环把字段的内容显示出来
while(rs.next()) {%>
<%=rs.getString(1)%>
<%=rs.getString(2)%>
<%="<br>"%>
<%}%>
<%="<br>数据库操作成功!"%>
<%rs.close(); //关闭结果集
stmt.close(); //关闭Statment
conn.close(); //关闭连接
%>
新闻一级标题发布系统实现对数据库的增删改查
前台调用jsp DB6配合jsp
构造容器 创建容器 扔进容器 取出
showFirstTitle.jsp
<table border="2">
<tr>
<th>ID号</th>
<th>新闻分类</th>
<th>创建者</th>
<th>创建时间</th>
</tr>
<%
NewsFirstTitleDB6 first=new NewsFirstTitleDB6();
List list=first.getAllFirstLevelTitleList();
if(list.size()!=0){
for(int i=0;i<list.size();i++){
FirstLevelTitle fTitle=(FirstLevelTitle)list.get(i);
%>
<tr>
<td><%=fTitle.getId()%></td>
<td><%=fTitle.getTitleName()%></td>
<td><%=fTitle.getCreator()%></td>
<td><%=fTitle.getCreateTime()%></td>
</tr>
<%}
}
%>
</table>
NewsFirstTitleDB6.java
package jmu;
import java.sql.*;
import java.util.*;
import jmu.FirstLevelTitle;
public class NewsFirstTitleDB6 {
/**从数据库中取出所有新闻一级标题,并封装在集合中返回 */
public List getAllFirstLevelTitleList() {
List<FirstLevelTitle> list = new ArrayList<FirstLevelTitle>();
Connection dbConnection = null;
PreparedStatement pStatement = null;
ResultSet res = null;
try {
dbConnection = ConnectionManager.getConnection();
String strSql = "select * from FirstLevelTitle order by CreateTime desc";
pStatement = dbConnection.prepareStatement(strSql);
res = pStatement.executeQuery();
while (res.next()) {
int id = res.getInt("id");
String title = res.getString(2);
String creator = res.getString("Creator");
//Date time = res.getDate("CreatTime");
java.util.Date time = res.getDate(4);
FirstLevelTitle fTitle = new FirstLevelTitle(id, title, creator, time);
list.add(fTitle);
}
} catch (SQLException sqlE) {
sqlE.printStackTrace();
} finally {
ConnectionManager.closeResultSet(res);
ConnectionManager.closeStatement(pStatement);
ConnectionManager.closeConnection(dbConnection);
}
return list;
}
}
addFirstTitle.jsp
<form name="form1" method="post" action="saveFirstLevelTitle.jsp">
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td width="45%" align="right">标题名:</td>
<td><input type="text" name="titlename" size="20"></td>
</tr>
<tr>
<td colspan=2 align=center>
<input type="submit" name="Submit" value="拟定" onClick="return checkOneTitle()">
<input type="reset" name="Reset" value="重置">
</td>
</tr>
</table>
<p align="center">注意:发布前请认真检查输入的标题是否对的</p>
</form>
保存页面 saveFirstTitle.jsp
<%
//指定请求的编码为GBK
request.setCharacterEncoding("GBK");
//获取用户输入
String titleName = request.getParameter("titlename");
FirstLevelTitle fTitle = new FirstLevelTitle();
fTitle.setTitleName(titleName);
fTitle.setCreator("管理员");
//向数据库中插入一行记录
FirstLevelTitleDbOpreation dbOpreation = new FirstLevelTitleDbOpreation();
int result = dbOpreation.insertOneRecord(fTitle);
//假如插入成功,跳转至成功页面;否则跳转至失败页面
if (result > 0) {
request.getRequestDispatcher("success.jsp").forward(request,response);
} else {
request.getRequestDispatcher("error.jsp").forward(request,response);
}
%>
FirstLevelTitleDbOpreation.java
public int insertOneRecord(FirstLevelTitle fTitle) {
int result = 0;
Connection con = null;
PreparedStatement pStatement = null;
try {
SimpleDateFormat HMFromat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String strCurrentTime = HMFromat.format( new Date());
con = ConnectionManager.getConnection();
String strSql ="insert into FirstLevelTitle values(?,?,?,?)";
pStatement = con.prepareStatement(strSql);
pStatement.setInt(1, getNewId());
pStatement.setString(2, fTitle.getTitleName());
pStatement.setString(3, fTitle.getCreator());
pStatement.setString(4, strCurrentTime);
result = pStatement.executeUpdate();
} catch (SQLException sqlE) {
sqlE.printStackTrace();
} finally {
ConnectionManager.closeStatement(pStatement);
ConnectionManager.closeConnection(con);
}
return result;
}
删除一级标题:delFirstTitle.jsp
<%
FirstLevelTitleDbOpreation fo=new FirstLevelTitleDbOpreation();
String firstLevelId=request.getParameter("id");
fo.deleteFirstLevelTitle(Integer.parseInt(firstLevelId));
request.getRequestDispatcher("showFirstTitle.jsp").forward(request,response);
%>
public void deleteFirstLevelTitle(int firstTitleId ){
Connection dbConnection = null;
PreparedStatement pStatementS = null;
PreparedStatement pStatementF = null;
//ResultSet res = null;
try {
dbConnection = ConnectionManager.getConnection();
String delSecondSql = "delete from SecondLevelTitle where ParentTitle=?";
pStatementS = dbConnection.prepareStatement(delSecondSql);
pStatementS.setInt(1, firstTitleId);
pStatementS.executeUpdate();
String delFirstSql="delete from FirstLevelTitle where id=?";
pStatementF = dbConnection.prepareStatement(delFirstSql);
pStatementF.setInt(1, firstTitleId);
pStatementF.executeUpdate();
}catch(Exception e){
e.printStackTrace();
}
}
更新一级标题:
<onclick=”window.open(‘updateFirstTitle.jsp?id=<%=id%>’)”>
<%
request.setCharacterEncoding("GBK");
FirstLevelTitleDbOpreation fo=new FirstLevelTitleDbOpreation();
String firstLevelId=(String)request.getParameter("id");
String titleName = request.getParameter("titlename");
String Creator=request.getParameter("creator");
fo.updateFirstTitle(Integer.parseInt(firstLevelId),titleName,Creator);
request.getRequestDispatcher("showFirstTitle.jsp").forward(request,response);
%>
public void updateFirstTitle(int firstLevelId,String titlename,String creator){
Connection con = null;
PreparedStatement pStatement = null;
try {
con = ConnectionManager.getConnection();
String strSql = "update FirstLevelTitle set TitleName = ? ,Creator = ? where Id = ?";
pStatement = con.prepareStatement(strSql);
pStatement.setString(1, titlename);
pStatement.setString(2, creator);
pStatement.setInt(3, firstLevelId);
int row = pStatement.executeUpdate();
System.out.println("成功更新了"+row+"行数据!");
} catch (SQLException sqlE) {
sqlE.printStackTrace();
} finally {
ConnectionManager.closeStatement(pStatement);
ConnectionManager.closeConnection(con);
}
}
2. DAO技术的开发环节
DAO由以下几部分组成:
①DatabaseConnection:专门负责数据库的打开与关闭操作的类。
②VO:重要由属性、setter、getter方法组成,VO类中的属性与表中的字段相相应,每一个VO类的对象都表达表中的每一条记录。
③DAO:重要定义操作的接口,定义一系列数据库的原子操作,如增长、修改、删除、按ID查询等。
④Impl:DAO接口的真实实现类,完毕具体的数据库操作,但是不负责数据库的打开和关闭。
Vo类:
package cn.jmu.vo;
public class Product {
//商品ID
protected int productID;
//商品编号
protected String serialNumber;
//商品名字
protected String name;
//商品品牌
protected String brand;
//商品型号
protected String model;
//商品价格
protected double price;
//商品的图片途径
protected String picture;
//商品描述
protected String description;
//商品无参构造
public Product() {
super();
}
//商品有参构造
public Product(String serialNumber, String name, String brand,
String model, double price, String picture, String description) {
super();
this.serialNumber = serialNumber;
this.name = name;
this.brand = brand;
this.model = model;
this.price = price;
this.picture = picture;
this.description = description;
}
public int getProductID() {
return productID;
}
public void setProductID(int productID) {
this.productID = productID;
}
public String getSerialNumber() {
return serialNumber;
}
public void setSerialNumber(String serialNumber) {
this.serialNumber = serialNumber;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getPicture() {
return picture;
}
public void setPicture(String picture) {
this.picture = picture;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
Impl:定义接口
package cn.jmu.dao;
import java.util.*;
import cn.jmu.vo.Product;
public interface IProductDAO {
public ArrayList getAllNextGoods(int page,int pageCount) throws Exception;
public ArrayList getAllGoods()throws Exception;
public int getPages(int pageCount)throws Exception;
public Product getOneGood(int pid)throws Exception;
public boolean addNew(Product product)throws Exception;
public boolean updateOneGood(Product product)
展开阅读全文