《JavaWeb编程技术》课后习题答案(15)
时间:2025-07-11
时间:2025-07-11
<%
String driver = "org.postgresql.Driver";
String dburl = "jdbc:postgresql://127.0.0.1:5432/bookstore";
String username = "bookstore";
String password = "bookstore";
try{
Class.forName(driver);
Connection dbconn = DriverManager.getConnection(
dburl,username,password);
Integer num = 0;
if(request.getParameter("param")!=null)
num = Integer.parseInt(request.getParameter("param"));
String sql = "{?=call my_factorial(?)}";
CallableStatement cstmt = dbconn.prepareCall(sql);
cstmt.setInt(2,num);
cstmt.registerOutParameter(1,java.sql.Types.INTEGER);
cstmt.execute();
int result = cstmt.getInt(1);
request.setAttribute("result",result);
}catch(ClassNotFoundException e1){
out.println(e1);
}catch(SQLException e2){
out.println(e2);
}catch(NumberFormatException e3){
out.println("输入不合法!");
}
%>
<p><%=request.getParameter("param")%>的阶乘为:
<%=request.getAttribute("result")%></p>
</body></html>
该页面的运行结果如下:
12. 略。
第8章习题解析
1. 答:表达式语言是JSP页面中使用的一种简洁的数据访问语言。它定义了运算符实现算术、关系等运算;可以对作用域变量、JavaBeans对象、集合的元素、请求参数、Cookie等进行简单的访问;还可以访问Java语言定义的函数(静态方法)。
2. 答:使用点(.)运算符可以访问Map对象一个键的值和bean
对象的属性值。使用