jsp代码问题
实验1:注册页面login.html包含文本框user,密码框psw,爱好复选框hobby。填写注册信息,提交给login.jsp。login.jsp页面读取用户填写的信...
实验1:注册页面login.html包含文本框user,密码框psw,爱好复选框hobby。填写注册信息,提交给login.jsp。login.jsp页面读取用户填写的信息,并输出到屏幕上。
实验2: 网上单选问答题的简单实现。考试页面test1.jsp只有三道题即可,点击提交由answer.jsp处理。每道题1分,测试结束输出考试成绩。
题目1:诗人李白是中国历史上哪个朝代的人
b. 宋朝 b.唐朝 c.明朝 d.元朝
其他题目学生自拟。
后续有加分 展开
实验2: 网上单选问答题的简单实现。考试页面test1.jsp只有三道题即可,点击提交由answer.jsp处理。每道题1分,测试结束输出考试成绩。
题目1:诗人李白是中国历史上哪个朝代的人
b. 宋朝 b.唐朝 c.明朝 d.元朝
其他题目学生自拟。
后续有加分 展开
2个回答
展开全部
test1.jsp
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Insert title here</title>
</head>
<body>
<form action="answer.jsp" method="post">
<table>
<tr>
<td>题目1:</td>
<td colSpan="4">诗人李白是中国历史上那个朝代的人</td>
</tr>
<tr>
<td></td>
<td><input type="radio" name="num1" value="宋朝" checked="checked"/>宋朝</td>
<td><input type="radio" name="num1" value="唐朝"/>唐朝</td>
<td><input type="radio" name="num1" value="明朝"/>明朝</td>
<td><input type="radio" name="num1" value="元朝"/>元朝</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>题目2:</td>
<td colSpan="3">字母a后边的字母为</td>
</tr>
<tr>
<td></td>
<td><input type="radio" name="num2" value="c" checked="checked"/>c</td>
<td><input type="radio" name="num2" value="b"/>b</td>
<td><input type="radio" name="num2" value="f"/>f</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>题目3:</td>
<td colSpan="3">字母f前边的字母为</td>
</tr>
<tr>
<td></td>
<td><input type="radio" name="num3" value="e" checked="checked"/>e</td>
<td><input type="radio" name="num3" value="a"/>a</td>
<td><input type="radio" name="num3" value="m"/>m</td>
</tr>
<tr>
<td><input type="submit" value="确认"/></td>
</tr>
</table>
</form>
</body>
</html>
answer.jsp
<%
request.setCharacterEncoding("gb2312");//编码转换,访止出现中文乱码
int point=0;
String right="回答正确,加一分";
String wrong="回答错误,不加分";
String isNum1Right;
String isNum2Right;
String isNum3Right;
if(request.getParameter("num1").equals("唐朝"))
{
isNum1Right=right;
point++;
}
else
{
isNum1Right=wrong;
}
if(request.getParameter("num2").equals("b"))
{
isNum2Right=right;
point++;
}
else
{
isNum2Right=wrong;
}
if(request.getParameter("num3").equals("e"))
{
isNum3Right=right;
point++;
}
else
{
isNum3Right=wrong;
}
%>
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Insert title here</title>
</head>
<body>
<table>
<tr>
<td>题目1:诗人李白是中国历史上那个朝代的人</td>
</tr>
<tr>
<td>你的答案为:<%=request.getParameter("num1") %></td>
<td style="color:red">
<%=isNum1Right %>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>题目2:诗人李白是中国历史上那个朝代的人</td>
</tr>
<tr>
<td>你的答案为:<%=request.getParameter("num2") %></td>
<td style="color:red">
<%=isNum2Right %>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>题目3:诗人李白是中国历史上那个朝代的人</td>
</tr>
<tr>
<td>你的答案为:<%=request.getParameter("num3") %></td>
<td style="color:red">
<%=isNum3Right %>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td style="color:red">你一共加答对了<%=point %>道题.得到<%=point %>分</td>
</tr>
</table>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Insert title here</title>
</head>
<body>
<form action="answer.jsp" method="post">
<table>
<tr>
<td>题目1:</td>
<td colSpan="4">诗人李白是中国历史上那个朝代的人</td>
</tr>
<tr>
<td></td>
<td><input type="radio" name="num1" value="宋朝" checked="checked"/>宋朝</td>
<td><input type="radio" name="num1" value="唐朝"/>唐朝</td>
<td><input type="radio" name="num1" value="明朝"/>明朝</td>
<td><input type="radio" name="num1" value="元朝"/>元朝</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>题目2:</td>
<td colSpan="3">字母a后边的字母为</td>
</tr>
<tr>
<td></td>
<td><input type="radio" name="num2" value="c" checked="checked"/>c</td>
<td><input type="radio" name="num2" value="b"/>b</td>
<td><input type="radio" name="num2" value="f"/>f</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>题目3:</td>
<td colSpan="3">字母f前边的字母为</td>
</tr>
<tr>
<td></td>
<td><input type="radio" name="num3" value="e" checked="checked"/>e</td>
<td><input type="radio" name="num3" value="a"/>a</td>
<td><input type="radio" name="num3" value="m"/>m</td>
</tr>
<tr>
<td><input type="submit" value="确认"/></td>
</tr>
</table>
</form>
</body>
</html>
answer.jsp
<%
request.setCharacterEncoding("gb2312");//编码转换,访止出现中文乱码
int point=0;
String right="回答正确,加一分";
String wrong="回答错误,不加分";
String isNum1Right;
String isNum2Right;
String isNum3Right;
if(request.getParameter("num1").equals("唐朝"))
{
isNum1Right=right;
point++;
}
else
{
isNum1Right=wrong;
}
if(request.getParameter("num2").equals("b"))
{
isNum2Right=right;
point++;
}
else
{
isNum2Right=wrong;
}
if(request.getParameter("num3").equals("e"))
{
isNum3Right=right;
point++;
}
else
{
isNum3Right=wrong;
}
%>
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Insert title here</title>
</head>
<body>
<table>
<tr>
<td>题目1:诗人李白是中国历史上那个朝代的人</td>
</tr>
<tr>
<td>你的答案为:<%=request.getParameter("num1") %></td>
<td style="color:red">
<%=isNum1Right %>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>题目2:诗人李白是中国历史上那个朝代的人</td>
</tr>
<tr>
<td>你的答案为:<%=request.getParameter("num2") %></td>
<td style="color:red">
<%=isNum2Right %>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>题目3:诗人李白是中国历史上那个朝代的人</td>
</tr>
<tr>
<td>你的答案为:<%=request.getParameter("num3") %></td>
<td style="color:red">
<%=isNum3Right %>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td style="color:red">你一共加答对了<%=point %>道题.得到<%=point %>分</td>
</tr>
</table>
</body>
</html>
展开全部
login.html代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>login.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<form action="login.jsp" >
user:<input type="text" name="user" /><br/>
psw:<input type="password" name="psw" /><br/>
hobby:<input type="checkbox" name="hobby" value="basketball">篮球<input type="checkbox" name="hobby" value="football"/>足球<br/>
<input type="submit" value="submit"/>
</form>
</body>
</html>
login.jsp的代码:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'login.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
String user = request.getParameter("user");
String psw = request.getParameter("psw");
String hobby [] = request.getParameterValues("hobby");
%>
user:<%=user %>
psw:<%=psw %>
hobby:
<%
for(int i=0;i<hobby.length;i++)
{
out.print(hobby[i]);
}
%>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>login.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<form action="login.jsp" >
user:<input type="text" name="user" /><br/>
psw:<input type="password" name="psw" /><br/>
hobby:<input type="checkbox" name="hobby" value="basketball">篮球<input type="checkbox" name="hobby" value="football"/>足球<br/>
<input type="submit" value="submit"/>
</form>
</body>
</html>
login.jsp的代码:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'login.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
String user = request.getParameter("user");
String psw = request.getParameter("psw");
String hobby [] = request.getParameterValues("hobby");
%>
user:<%=user %>
psw:<%=psw %>
hobby:
<%
for(int i=0;i<hobby.length;i++)
{
out.print(hobby[i]);
}
%>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询