- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建一个测验应用程序。这里有 5 个 jsp 页面,有 5 个不同的测验。如果我使用 1 个 jsp 页面和结果页面,它工作正常......即;它从 QuizPage5.jsp 重定向并在 ResultPage.jsp 中显示结果。我需要将 QuizPage1.jsp、QuizPage2.jsp、QuizPage3.jsp、QuizPage4.jsp 和 QuizPage5.jsp 的所有结果显示到 ResultPage.jsp。
我用过
在jsp1中传递值。
<form action="">
<input type="hidden" name="hidden" value="hidden">
<input type="submit" value="submit"></form>
在jsp2中获取值
String value=request.getParameter("hidden");
但是,我得到了java.lang.NullPointerException
这是我的代码..
QuizPage1.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script language="JavaScript">
function check()
{
var radio_choice = false;
for (counter = 0; counter < myform.grp.length; counter++)
{
if (myform.grp[counter].checked)
radio_choice = true;
}
if (!radio_choice)
{
alert("Please select one.")
return (false);
}
return(true);
}
</script>
</head>
<body>
<h3>Quiz No.1</h3>
Q1.Which one of the following is the Capital of India?<br><br>
<form action="QuizPage2.jsp" method="post" name="myform" onsubmit="return check();">
<input type="radio" name="grp" value="New Delhi" >New Delhi<br>
<input type="radio" name="grp" value="Kolkata" >Kolkata<br>
<input type="radio" name="grp" value="Chennai" >Chennai<br>
<input type="radio" name="grp" value="Mumbai" >Mumbai<br>
<br><br><input type="submit" value="Next Question">
<input type="hidden" name="hidden" value="grp">
<input type="submit" value ="Back" onclick="window.history.back();"/>
</form>
</body>
</html>
QuizPage2.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script language="JavaScript">
function check()
{
var radio_choice = false;
for (counter = 0; counter < myform2.grp2.length; counter++)
{
if (myform2.grp2[counter].checked)
radio_choice = true;
}
if (!radio_choice)
{
alert("Please select any one Answer");
return (false);
}
return(true);
}
</script>
</head>
<body>
<h3>Quiz No.2</h3>
Q2. Where is Chennai Located?<br><br>
<form action="QuizPage3.jsp"method="post" name="myform2" onsubmit="return check();">
<input type="radio" name="grp2" value="Karnataka" >Karnataka<br>
<input type="radio" name="grp2" value="Tamilnadu" >Tamilnadu<br>
<input type="radio" name="grp2" value="Andhra Pradesh" >Andhra Pradesh<br>
<input type="radio" name="grp2" value="Maharashtra" >Maharashtra<br>
<br><br><input type="submit" value="Next Question">
<input type="hidden" name="hidden" value="grp2">
<input type="submit" value ="Back" onclick="window.history.back();"/>
</form>
<%
String s1=request.getParameter("grp");
%>
</body>
</html>
QuizPage3.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script language="JavaScript">
function check()
{
var radio_choice = false;
for (counter = 0; counter < myform3.grp3.length; counter++)
{
if (myform3.grp3[counter].checked)
radio_choice = true;
}
if (!radio_choice)
{
alert("Please select any one Answer");
return (false);
}
return(true);
}
</script>
</head>
<body>
<h3>Quiz No.3</h3>
Q3. What is the largest state in the USA<br><br>
<form action="QuizPage4.jsp"method="post" name="myform" onsubmit="return check();">
<input type="radio" name="grp3" value="New York" >New York<br>
<input type="radio" name="grp3" value="Alaska" >Alaska<br>
<input type="radio" name="grp3" value="California" >California<br>
<input type="radio" name="grp3" value="Melbourne" >Melbourne<br>
<br><br><input type="submit" value="Next Question">
<input type="hidden" name="hidden" value="grp3">
<input type="submit" value ="Back" onclick="window.history.back();"/>
</form>
<%
String s2=request.getParameter("grp2");
%>
</body>
</html>
QuizPage4.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script language="JavaScript">
function check()
{
var radio_choice = false;
for (counter = 0; counter < myform4.grp4.length; counter++)
{
if (myform4.grp4[counter].checked)
radio_choice = true;
}
if (!radio_choice)
{
alert("Please select any one Answer");
return (false);
}
return(true);
}
</script>
</head>
<body>
<h3>Quiz No.4</h3>
Q4. The famous Dilwara Temples are situated in<br><br>
<form action="QuizPage5.jsp"method="post" name="myform" onsubmit="return check();">
<input type="radio" name="grp4" value="Uttar Pradesh" >Uttar Pradesh<br>
<input type="radio" name="grp4" value="Maharashtra" >Maharashtra<br>
<input type="radio" name="grp4" value="Andhra Pradesh" >Andhra Pradesh<br>
<input type="radio" name="grp4" value="Rajasthan" >Rajasthan<br>
<br><br><input type="submit" value="Next Question">
<input type="hidden" name="hidden" value="grp4">
<input type="submit" value ="Back" onclick="window.history.back();"/>
</form>
<%
String s3=request.getParameter("grp3");
%>
</body>
</html>
QuizPage5.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script language="JavaScript">
function check()
{
var radio_choice = false;
for (counter = 0; counter < myform5.grp5.length; counter++)
{
if (myform5.grp5[counter].checked)
radio_choice = true;
}
if (!radio_choice)
{
alert("Please select any one Answer");
return (false);
}
return(true);
}
</script>
</head>
<body>
<h3>Quiz No.5</h3>
Q5. The Indian Institute of Science is located at<br><br>
<form action="ResultPage.jsp"method="post" name="myform" onsubmit="return check();">
<input type="radio" name="grp5" value="Chennai" >Chennai<br>
<input type="radio" name="grp5" value="Bangalore" >Bangalore<br>
<input type="radio" name="grp5" value="Mumbai" >Mumbai<br>
<input type="radio" name="grp5" value="Hyderabad" >Hyderabad<br>
<br><br><input type="submit" value="Show Result">
<input type="hidden" name="hidden" value="grp5"/>
</form>
<%
String s4=request.getParameter("grp4");
%>
</body>
</html>
结果页.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Quiz Result</title>
</head>
<body>
<%
String answer="New Delhi";
String s1=request.getParameter("grp");
if(s1.equals(answer))
{
out.println("Correct Answer");
}
else
{out.println("Wrong Answer! The Correct Answer is :"+answer);
}
%>
<%
String answer2="Tamilnadu";
String s2=request.getParameter("grp2");
if(s2.equals(answer2))
{
out.println("Correct Answer");
}
else
{out.println("Wrong Answer! The Correct Answer is :"+answer2);
}
%>
<%
String answer3="Alaska";
String s3=request.getParameter("grp3");
if(s3.equals(answer3))
{
out.println("Correct Answer");
}
else
{out.println("Wrong Answer! The Correct Answer is :"+answer3);
}
%>
<%
String answer4="Rajasthan";
String s4=request.getParameter("grp4");
if(s4.equals(answer4))
{
out.println("Correct Answer");
}
else
{out.println("Wrong Answer! The Correct Answer is :"+answer4);
}
%>
<%
String answer5="Bangalore";
String s5=request.getParameter("grp5");
if(s5.equals(answer5))
{
out.println("Correct Answer");
}
else
{out.println("Wrong Answer! The Correct Answer is :"+answer5);
}
%>
</body>
</html>
非常感谢您的帮助。提前致谢
最佳答案
如果您希望可以跨多个页面访问数据,请考虑使用 session 来存储数据。例如,如果 page1.jsp 向 page2.jsp 提交表单参数“page1Result”,则在 page2.jsp 中执行以下操作:
String page1Result = request.getParameter("page1Result");
request.getSession().setAttribute("page1Result", page1Result);
然后在某个时刻(例如第 5 页),您可以按如下方式访问 page1 值:
String page1Value = (String)request.getSession().getAttribute("page1Result);
================================================== ===================================因此,将其应用到您的代码中:
在page2 jsp中,将文件末尾的scriptlet更改为:
<%
String s1=request.getParameter("grp");
request.getSession().setAttribute("s1", s1);
%>
在第 3 页 JSP 中,将脚本 let 更改为:
<%
String s2=request.getParameter("grp2");
request.getSession().setAttribute("s2", s2);
%>
等等。
最后在 ResultPage.jsp 上(仅显示答案 2 的一行示例)
out.println("Wrong Answer! The Correct Answer for question 2 is :"+session.getAttribute("s2"));
关于java - 如何将前一个jsp页面的值检索到结果页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19993935/
前一段时间写过一篇文章《 实战,一个高扩展、可视化低代码前端,详实、完整 》,得到了很多朋友的关注。 其中的逻辑编排部分过于简略,不少朋友希望能写一些关于逻辑编排的内容,本文就详细讲述一下逻辑
我正在尝试以下 Java 片段: int[] testArray={10,20,30,40}; int i= 0; testArray[i++]= testArray[i++]+1; System.o
我想知道我是否可以通过某种方式在 C++ 中进行前/后函数调用。我有一个包含很多函数的包装器类,在每次调用包装器函数后,我应该调用另一个始终相同的函数。 所以我不想像这样对每个函数调用 postFun
我有一个像这样的头文件: #pragma once #include "gamestate.h" #include "ExitListener.h" class InitialGameState :
学习左值和右值。定义是任何可以是“地址”的东西都是左值,否则就是右值。 我检查了运算符的优先级,前缀和后缀增量都比“地址”运算符具有更高的优先级。 对于下面的两个例子,谁能解释一下为什么第一个“&++
在我的学习过程中,我遇到了前后迭代器,我想知道是否有办法让它们就地创建容器元素。从文档来看,容器似乎需要实现 push_back 函数才能与 back_iterator 一起使用。但是有没有一种方法可
我有两个关于 Java 中运算符优先级的类似问题。 第一个: int X = 10; System.out.println(X++ * ++X * X++); //it prints 1440 根据
请放轻松,不要对我开枪,因为我还是新手。 当我运行这段代码时,我完全糊涂了,终生无法弄清楚为什么: int y = 9; cout << "++y = " << ++y << "\n--y = " <
两种表达方式有区别吗: (*x)++ 和 ++(*x) 我可以看到这两个语句都替换了 *x 中 (*x+1) 的内容。但是它们之间有什么区别吗? 最佳答案 (*x)++ 计算为*x的值;作为副作用,*
我有一个如下所示的数据集: Date CONSUMER DISCR CONSUMER STAPLES ENERGY FINANCIALS HEALTH CARE
我希望检查名称字段中输入的前两个字符是否为字母 - 除此之外没有什么区别(空格、'、- 等都是公平的游戏)。这是我到目前为止所拥有的,但它不起作用。想法?谢谢! if (document.form01
我制作了一个简单的脚本,为像素和所有附近的像素着色为相同的颜色 Click foto
我需要编写一个循环,以下列格式输出从昨天算起的最近 30 天: 2014-02-02 2014-02-03 2014-02-04 ... 2014-03-04 我想我需要像这样使用循环: for ($
我正在做一些练习,但我对这个感到困惑: public static int f (int x, int y) { int b=y--; while (b>0) { if (x%2!=0
我需要一个 4 个字符的正则表达式。前 3 个字符必须是数字,最后 1 个字符必须是字母或数字。 我形成了这个,但它不起作用 ^([0-9]{3}+(([a-zA-Z]*)|([0-9]*)))?$
我需要编写一个循环,以下列格式输出从昨天算起的最近 30 天: 2014-02-02 2014-02-03 2014-02-04 ... 2014-03-04 我想我需要像这样使用循环: for ($
我有下面的程序,我试图找到前 1000 个素数的总和。在代码中,解决方案1和2有什么区别?为什么我不应该将 count 变量放在 if 条件之外?如果我把变量放在 if 之外,我显然没有得到我需要的答
这个问题在这里已经有了答案: Replace First N Occurrences in the String (7 个答案) 关闭 4 年前。 我有一个如下的字符串 const str = '_
我正在尝试测量以纳秒为单位的平均访问延迟,但在第一次迭代后我收到“段错误(核心转储)”。我错过了什么吗?我是否滥用了指针。这是导致错误的函数: #include #include #include
我有一个 SQL 问题 (MySQL)。我如何从下表创建一个新表(表名称:“well_master_prod_inj”)。 我需要按井名和日期聚合数据。我希望每个井名只有一行数据以及显示以下数据的列:
我是一名优秀的程序员,十分优秀!