3.6 习题
3.6习题
1、编写一个页面输出单选试题,再编写一个信息处理页面获取用户做出的选择,并统计得分。其运行结果如图所示。


参考代码:
exercise.jsp
点击查看代码
<%@ page language="java" contentType="text/html;charset=GBK"%>
<html>
<head>
<title>exercise</title>
</head>
<body>
<form name="form" method="post" action="exercise1.jsp">
<p>(1)属于JavaEE的开发技术是:</p>
<input type="radio" name="No.1" value="a">ASP.NET
<input type="radio" name="No.1" value="b">JSP
<input type="radio" name="No.1" value="c">PHP
<input type="radio" name="No.1" value="d">CSS
<p>(2)以下不属于数据库管理系统是:</p>
<input type="radio" name="No.2" value="a">LINUX
<input type="radio" name="No.2" value="b">MYSQL
<input type="radio" name="No.2" value="c">ORACLE
<input type="radio" name="No.2" value="d">DB2
<p><input type="submit" name="Submit" value="提交答案"></p>
</form>
</body>
</html>
exercise.jsp
点击查看代码
<%@ page language="java" contentType="text/html;charset=GBK"%>
<html>
<head>
<title>exercise1</title>
</head>
<body>
<%
request.setCharacterEncoding("GBK");
String s1 = request.getParameter("No.1");
String s2 = request.getParameter("No.2");
if(s1 == null)
s1 = "";
if(s2 == null)
s2 = "";
int score = 0;
if(s1.equals("b"))
score++;
if(s2.equals("a"))
score++;
%>
<center><p>你得了<%= score%>分</p></center>
</body>
</html>

浙公网安备 33010602011771号