Geocortext IMF framework Null reference exception - java

Still having issues with this problem. Please help if you can.
So I am trying to fix a piece of code using the Geocortex IMF framework. I get an error on line 40 which is basically pulling a null exception. It is a mix of java and html. For some reason I can't seem to find out why the error is pulling up a null. Even if I load the variable with data, it still stops at rs = activeLayer.getRecordset();
Here is the Address Form they fill out and submit
<%# page errorPage="imfError.jsp" %>
<%
/*
Program: afoAddressForm.jsp
Purpose: Displays a page to the user to input address values for a
USAddress type of geocoding query.
Usage: </>
History:
*/
String layerId = request.getParameter("layerid");
String scale = request.getParameter("scale");
if (layerId == null) {
throw new Exception("Missing layerid parameter.");
}
if (scale == null) {
throw new Exception("Missing scale parameter.");
}
%>
<jsp:include page="/imfCopyright.jsp"/>
<html>
<head>
<title></title>
<meta http-equiv="Content-Style-Type" content="text/css">
<link href="../../../imfStyle.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/javascript">
function doNothing() {
}
function submitForm() {
var strStreetName = document.frm.streetName.value;
if (strStreetName == "") {
alert("Please enter street name." );
document.frm.streetNumber.focus();
} else {
document.frm.action = "afoAddress.jsp?streetName="+strStreetName;
document.frm.submit();
}
}
</script>
</head>
<body bgcolor="#FFFFFF" alink="#ff0000" link="#ff0000" vlink="#ff0000">
<form name="frm" action="JavaScript:doNothing()" method="post">
<input type="hidden" name="layerid" value="<%= layerId %>">
<input type="hidden" name="scale" value="<%= scale %>">
<table width="95%" border="0" cellspacing="0" cellpadding="0">
<center>
<tr><td align="left" class="bb11">Zoom To Street<hr></td></tr>
<tr><td height="10"></td></tr>
<tr>
<td align="left" valign="top" class="bn8">
Enter the street name where you wish to centre the map.
If matching streets are found, you will be shown a list
of matching street names for you to choose where to
zoom the map to.
</td>
</tr>
<tr><td height="10"></td></tr>
<tr><td align="center" class="bb8">Street Name</td></tr>
<tr><td align="center" class="bb8"><input name="streetName" size="15" maxLength=40 value=""></td></tr>
<tr><td height="10"></td></tr>
<tr><td align="center" ><input name="btn" type="button" value="Submit" onclick="JavaScript:submitForm()"></td></tr>
<tr><td height="10"></td></tr>
</center>
</table>
</form>
</body>
</html>
Here is what the address form submits to
<%# page import="com.moximedia.aims.*" %>
<%
/*
Program: imfGeocodeUSAddress.jsp
An Internet Mapping Framework (IMF) system script
Copyright 2002 Province of British Columbia - all rights reserved
Purpose: Displays a page of positions matching the address
input by the user for USAddress geocoding styles.
History: 20020610 Cates: original coding
20030724 Cates: send user selection to separate script for labelling.
20040525 Cates: changed frame reference top to parent
20050103 Cates: added type to stylesheet link.
*/
String layerId = request.getParameter("layerid");
String scale = request.getParameter("scale");
String StreetName = request.getParameter("streetName");
AimsMap map = (AimsMap) (session.getAttribute("map"));
AimsFeatureLayer activeLayer = (AimsFeatureLayer) map.getLayers().getLayer(layerId);
AimsRecordset rs = null;
AimsFilter streetFilter = new AimsFilter();
if (activeLayer != null && activeLayer.getFilter()!= null) {
streetFilter = (AimsFilter) activeLayer.getFilter();
}
String query_String="";
if (StreetName == null) {
return;
}else{
StreetName = StreetName.toUpperCase();
query_String = "upper(FENAME) = '" + StreetName +"'";
//query_String = "FENAME like '%" + StreetName +"%'";
streetFilter.setWhereExpression(query_String);
}
// do the query, and whatever we need to do with the data
rs = activeLayer.getRecordset();
rs.clear();
rs.clearFilter();
rs.setMaximumResults(100);
rs.setBufferSize(rs.getMaximumResults());
rs.setFilter(streetFilter);
rs.query();
int count = 0;
rs.moveFirst();
while(!rs.EOF()) {
count++;
rs.moveNext();
}
%>
<jsp:include page="/imfCopyright.jsp"/>
<html>
<head>
<title></title>
<meta http-equiv="Content-Style-Type" content="text/css">
<link href="imfStyle.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/javascript">
function submitForm() {
document.query.submit();
}
</script>
</head>
<body onload="submitForm();">
<form name="query" method="post" action="afoSelectDefaultFind.jsp">
<input type="hidden" name="layerid" value="<%= layerId%>" >
<input type="hidden" name="rec" value="1" >
<input type="hidden" name="total" value="<%=count%>" >
<input type="hidden" name="query_String" value="<%=query_String%>" >
</form>
</body>
</html>
The error is when you hit submit on the form the java.lang.NullPointerException error pops up and put it on line 40 which is rs = activeLayer.getRecordset();. Any help with this would be great.

Well, my guess is that activeLayer is null and then you are calling getRecordset() on a null object reference. Can you try to debug
map.getLayers().getLayer(layerId);
To make sure that it is returning something?

As Chris Thompson points out, the issue is almost certainly that the layer is null. Check that your AXL file has the right layers and layerIds. (Sorry, I know ArcIMS, but I'm not familiar with the Geocortex framework.)
Also, you should add code to check if activeLayer is null and throw a different exception than NullPointerException, since that will make the error that much more obvious to the next programmer that comes along. Interesting that the streetFilter isn't applied if activeLayer is null, so somebody thought about this at some point.

Related

getting Russian input from web into java applcation

I obviously am missing something here. I have a web app where the input for a form may be in English or, after a keyboard switch, Russian. The meta tag for the page is specifying that the page is UTF-8. That does not seem to matter.
If I type in "вв", two of the unicode character: CYRILLIC SMALL LETTER VE
What do I get? A string. I call getCodePoints().toArray() and I get:
[208, 178, 208, 178]
If I call chars().toArray[], I get the same.
What the heck?
I am completely in control of the web page, but of course there will be different browsers. But how can I get something back from the web page that will let me get the proper cyrillic characters?
This is on java 1.8.0_312. I can upgrade some, but not all the way to the latest java.
The page is this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>Cards</title>
<link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity = "sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin = "anonymous" />
<link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity = "sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin = "anonymous" />
<script src = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity = "sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin = "anonymous">
</script>
<meta http-equiv = "Content-Type" content = "text/html; charset=UTF-8" />
<style>.table-nonfluid { width: auto !important; }</style>
</head>
<body>
<div style = "padding: 25px 25px 25px 25px;">
<h2 align = "center">Cards</h2>
<div style = "white-space: nowrap;">
Home
<div>
<form name="f_3_1" method="post" action="/cgi-bin/WebObjects/app.woa/wo/ee67KCNaHEiW1WdpdA8JIM/2.3.1">
<table class = "table" border = "1" style = "max-width: 50%; font-size: 300%; text-align: center;">
<tr>
<td>to go</td>
</tr>
<tr>
<td><input size="25" type="text" name="3.1.5.3.3" /></td>
</tr>
<td>
<input type="submit" value="Submit" name="3.1.5.3.5" /> Skip
</td>
</table>
<input type="hidden" name="wosid" value="ee67KCNaHEiW1WdpdA8JIM" />
</form>
</div>
</div>
</div>
</body>
</html>
Hm. Well, here is at least part of the story.
I have this code:
System.out.println("start: " + start);
int[] points = start.chars().toArray();
byte[] next = new byte[points.length];
int idx = 0;
System.out.print("fixed: ");
for (int p : points) {
next[idx] = (byte)(p & 0xff);
System.out.print(Integer.toHexString(next[idx]) + " ");
idx++;
}
System.out.println("");
The output is:
start: вв
fixed: ffffffd0 ffffffb2 ffffffd0 ffffffb2
And the UTF-8 value for "В", in hex, is d0b2.
So, there it is. The question is, why is this not more easily accessible? Do I really have to put this together byte-pair by byte-pair?
If the string is already in UTF-8, as I think we can see it is, why does the codePoints() method not give us, you know, the codePoints?
Ok, so now I do:
new String(next, StandardCharsets.UTF_8);
and I get the proper string. But it still seems strange that codePoints() gives me an IntStream, but if you use these things as int values, it is broken.
It was a problem with the frameworks I was using. I thought I was setting the request and response content type to utf-8 but I was not.

HTMLunit Help Script for checking available classes

I am a bit out of sync with web programming and getting into HTMLUnit is a bit more confusing than I thought it would be.
Essentially I missed registering a class and need to be notified the moment a space opens but prior to getting to that page dump I need to submit a form with two radio inputs ( with the options "Spring Semester 2019" and the "All Classes").
I am in a weird spot where I want to learn more but also need a working script, so a combination of an answer plus some resources I might not be utilizing would be awesome! For example when I do get to the next page how do I download the html file raw and access the required data like number of spots filled and available in xyz class.
https://mystudentrecord.ucmerced.edu/pls/PROD/xhwschedule.p_selectsubject
Here is the monkey little program I wrote to get my feet a bit wet:
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
import java.io.IOException;
import java.net.MalformedURLException;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
public class hateMerced {
public void submittingForm() throws Exception {
}
public static void main(final String[] args) throws IOException {
final WebClient webClient = new WebClient();
// Get the first page
HtmlPage page1 = webClient.getPage("https://mystudentrecord.ucmerced.edu/pls/PROD/xhwschedule.p_selectsubject");
// Get the form that we are dealing with and within that form,
// find the submit button and the field that we want to change.
final HtmlForm form = page1.getFormByName("xhwschedule.P_ViewSchedule");
HtmlRadioButtonInput radioButton = (HtmlRadioButtonInput) page1.getElementById("201910");
radioButton.setChecked(true);
HtmlRadioButtonInput radioButton2 = (HtmlRadioButtonInput) page1.getElementById("N");
radioButton2.setChecked(true);
final HtmlSubmitInput button = form.getInputByName("View Class Schedule");
// Now submit the form by clicking the button and get back the second page.
// final HtmlPage page2 = button.click();
webClient.close();
}
}
And Here is the lovely error I get:
Jan 16, 2019 1:09:57 AM com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter error
SEVERE: error: message=[illegally formed XML syntax] sourceName=[script in https://mystudentrecord.ucmerced.edu/pls/PROD/xhwschedule.p_selectsubject from (11, 54) to (39, 10)] line=[38] lineSource=[// End script hiding -->] lineOffset=[24]
Exception in thread "main" ======= EXCEPTION START ========
Exception class=[net.sourceforge.htmlunit.corejs.javascript.EvaluatorException]
com.gargoylesoftware.htmlunit.ScriptException: illegally formed XML syntax (script in https://mystudentrecord.ucmerced.edu/pls/PROD/xhwschedule.p_selectsubject from (11, 54) to (39, 10)#38)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:892)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:616)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:534)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:723)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:689)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:735)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScript(HtmlPage.java:922)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeInlineScriptIfNeeded(HtmlScript.java:316)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:396)
at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:246)
at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:267)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:802)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:758)
at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1194)
at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1134)
at net.sourceforge.htmlunit.cyberneko.filters.DefaultFilter.endElement(DefaultFilter.java:221)
at net.sourceforge.htmlunit.cyberneko.filters.NamespaceBinder.endElement(NamespaceBinder.java:314)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3179)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2132)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner.scanDocument(HTMLScanner.java:939)
at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:452)
at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:403)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:1001)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:250)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:196)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:267)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:158)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:531)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:398)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:315)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:466)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:448)
at FuckMerced.main(FuckMerced.java:34)
Caused by: net.sourceforge.htmlunit.corejs.javascript.EvaluatorException: illegally formed XML syntax (script in https://mystudentrecord.ucmerced.edu/pls/PROD/xhwschedule.p_selectsubject from (11, 54) to (39, 10)#38)
at com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter.error(StrictErrorReporter.java:65)
at net.sourceforge.htmlunit.corejs.javascript.Parser.addError(Parser.java:260)
at net.sourceforge.htmlunit.corejs.javascript.Parser.addError(Parser.java:232)
at net.sourceforge.htmlunit.corejs.javascript.Parser.addError(Parser.java:228)
at net.sourceforge.htmlunit.corejs.javascript.TokenStream.getNextXMLToken(TokenStream.java:1287)
at net.sourceforge.htmlunit.corejs.javascript.TokenStream.getFirstXMLToken(TokenStream.java:1136)
at net.sourceforge.htmlunit.corejs.javascript.Parser.xmlInitializer(Parser.java:2666)
at net.sourceforge.htmlunit.corejs.javascript.Parser.unaryExpr(Parser.java:2641)
at net.sourceforge.htmlunit.corejs.javascript.Parser.mulExpr(Parser.java:2568)
at net.sourceforge.htmlunit.corejs.javascript.Parser.addExpr(Parser.java:2552)
at net.sourceforge.htmlunit.corejs.javascript.Parser.shiftExpr(Parser.java:2533)
at net.sourceforge.htmlunit.corejs.javascript.Parser.relExpr(Parser.java:2508)
at net.sourceforge.htmlunit.corejs.javascript.Parser.eqExpr(Parser.java:2480)
at net.sourceforge.htmlunit.corejs.javascript.Parser.bitAndExpr(Parser.java:2469)
at net.sourceforge.htmlunit.corejs.javascript.Parser.bitXorExpr(Parser.java:2458)
at net.sourceforge.htmlunit.corejs.javascript.Parser.bitOrExpr(Parser.java:2447)
at net.sourceforge.htmlunit.corejs.javascript.Parser.andExpr(Parser.java:2436)
at net.sourceforge.htmlunit.corejs.javascript.Parser.orExpr(Parser.java:2425)
at net.sourceforge.htmlunit.corejs.javascript.Parser.condExpr(Parser.java:2389)
at net.sourceforge.htmlunit.corejs.javascript.Parser.assignExpr(Parser.java:2345)
at net.sourceforge.htmlunit.corejs.javascript.Parser.expr(Parser.java:2324)
at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1282)
at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:1136)
at net.sourceforge.htmlunit.corejs.javascript.Parser.parse(Parser.java:673)
at net.sourceforge.htmlunit.corejs.javascript.Parser.parse(Parser.java:594)
at net.sourceforge.htmlunit.corejs.javascript.Context.compileImpl(Context.java:2601)
at net.sourceforge.htmlunit.corejs.javascript.Context.compileString(Context.java:1583)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory$TimeoutContext.compileString(HtmlUnitContextFactory.java:216)
at net.sourceforge.htmlunit.corejs.javascript.Context.compileString(Context.java:1572)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$1.doRun(JavaScriptEngine.java:714)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:877)
... 34 more
Enclosed exception:
net.sourceforge.htmlunit.corejs.javascript.EvaluatorException: illegally formed XML syntax (script in https://mystudentrecord.ucmerced.edu/pls/PROD/xhwschedule.p_selectsubject from (11, 54) to (39, 10)#38)
at com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter.error(StrictErrorReporter.java:65)
at net.sourceforge.htmlunit.corejs.javascript.Parser.addError(Parser.java:260)
at net.sourceforge.htmlunit.corejs.javascript.Parser.addError(Parser.java:232)
at net.sourceforge.htmlunit.corejs.javascript.Parser.addError(Parser.java:228)
at net.sourceforge.htmlunit.corejs.javascript.TokenStream.getNextXMLToken(TokenStream.java:1287)
at net.sourceforge.htmlunit.corejs.javascript.TokenStream.getFirstXMLToken(TokenStream.java:1136)
at net.sourceforge.htmlunit.corejs.javascript.Parser.xmlInitializer(Parser.java:2666)
at net.sourceforge.htmlunit.corejs.javascript.Parser.unaryExpr(Parser.java:2641)
at net.sourceforge.htmlunit.corejs.javascript.Parser.mulExpr(Parser.java:2568)
at net.sourceforge.htmlunit.corejs.javascript.Parser.addExpr(Parser.java:2552)
at net.sourceforge.htmlunit.corejs.javascript.Parser.shiftExpr(Parser.java:2533)
at net.sourceforge.htmlunit.corejs.javascript.Parser.relExpr(Parser.java:2508)
at net.sourceforge.htmlunit.corejs.javascript.Parser.eqExpr(Parser.java:2480)
at net.sourceforge.htmlunit.corejs.javascript.Parser.bitAndExpr(Parser.java:2469)
at net.sourceforge.htmlunit.corejs.javascript.Parser.bitXorExpr(Parser.java:2458)
at net.sourceforge.htmlunit.corejs.javascript.Parser.bitOrExpr(Parser.java:2447)
at net.sourceforge.htmlunit.corejs.javascript.Parser.andExpr(Parser.java:2436)
at net.sourceforge.htmlunit.corejs.javascript.Parser.orExpr(Parser.java:2425)
at net.sourceforge.htmlunit.corejs.javascript.Parser.condExpr(Parser.java:2389)
at net.sourceforge.htmlunit.corejs.javascript.Parser.assignExpr(Parser.java:2345)
at net.sourceforge.htmlunit.corejs.javascript.Parser.expr(Parser.java:2324)
at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1282)
at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:1136)
at net.sourceforge.htmlunit.corejs.javascript.Parser.parse(Parser.java:673)
at net.sourceforge.htmlunit.corejs.javascript.Parser.parse(Parser.java:594)
at net.sourceforge.htmlunit.corejs.javascript.Context.compileImpl(Context.java:2601)
at net.sourceforge.htmlunit.corejs.javascript.Context.compileString(Context.java:1583)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory$TimeoutContext.compileString(HtmlUnitContextFactory.java:216)
at net.sourceforge.htmlunit.corejs.javascript.Context.compileString(Context.java:1572)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$1.doRun(JavaScriptEngine.java:714)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:877)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:616)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:534)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:723)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:689)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:735)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScript(HtmlPage.java:922)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeInlineScriptIfNeeded(HtmlScript.java:316)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:396)
at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:246)
at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:267)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:802)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:758)
at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1194)
at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1134)
at net.sourceforge.htmlunit.cyberneko.filters.DefaultFilter.endElement(DefaultFilter.java:221)
at net.sourceforge.htmlunit.cyberneko.filters.NamespaceBinder.endElement(NamespaceBinder.java:314)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3179)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2132)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner.scanDocument(HTMLScanner.java:939)
at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:452)
at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:403)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:1001)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:250)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:196)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:267)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:158)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:531)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:398)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:315)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:466)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:448)
at FuckMerced.main(FuckMerced.java:34)
== CALLING JAVASCRIPT ==
<!-- Hide JavaScript from older browsers
var submitcount=0;
function checkSubmit() {
if (submitcount == 0)
{
submitcount++;
return true;
}
else
{
alert("Your changes have already been submitted.");
return false;
}
}
// End script hiding -->
<script type="text/javascript">
<!-- Hide JavaScript from older browsers
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-31337262-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
// End script hiding -->
======= EXCEPTION END ========
And here is the HTML of the form I am accessing in case the link is being weird:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML lang="en">
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META HTTP-EQUIV="Pragma" NAME="Cache-Control" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" NAME="Cache-Control" CONTENT="no-cache">
<LINK REL="stylesheet" HREF="/css/web_defaultapp.css" TYPE="text/css">
<LINK REL="stylesheet" HREF="/css/web_defaultprint.css" TYPE="text/css" media="print">
<TITLE>Search Courses by Subject</TITLE>
<META HTTP-EQUIV="Content-Script-Type" NAME="Default_Script_Language" CONTENT="text/javascript">
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!-- Hide JavaScript from older browsers
var submitcount=0;
function checkSubmit() {
if (submitcount == 0)
{
submitcount++;
return true;
}
else
{
alert("Your changes have already been submitted.");
return false;
}
}
// End script hiding -->
<script type="text/javascript">
<!-- Hide JavaScript from older browsers
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-31337262-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
// End script hiding -->
</script>
</HEAD>
<BODY>
<DIV class="headerwrapperdiv">
<TABLE CLASS="plaintable" SUMMARY="This table displays Menu Items and Banner Search textbox."
WIDTH="100%">
<TR>
<TD CLASS="pldefault"></TD>
<TD CLASS="pldefault"><p class="rightaligntext"></p>
</TD></TR></TABLE>
</DIV>
<DIV class="pagetitlediv">
<TABLE CLASS="plaintable" SUMMARY="This table displays title and static header displays."
WIDTH="100%">
<TR>
<TD CLASS="pldefault"><br /><br /><br /></TD>
<TD CLASS="pldefault"> </TD>
<TD CLASS="pldefault"><p class="rightaligntext"></p>
<DIV class="staticheaders">
</div>
</TD></TR><TR>
<TD width="100%" colSpan=3> </TD>
</TR></TABLE>
</DIV>
<DIV class="pagebodydiv">
UC Merced Schedule--Search Courses by Term or Subject <H4>
Interested in UC Online courses offered at other UC campuses? Check out information at UC Online.
<FORM ACTION="xhwschedule.P_ViewSchedule" METHOD="post">
<TABLE CLASS="plaintable" >
<TR>
<TD COLSPAN="2" CLASS="pldefault">Select a Term:</TD>
</TR>
<TR>
<TD CLASS="pldefault">
<INPUT TYPE="radio" NAME="validterm" VALUE="201820" CHECKED>
<TD CLASS="pldefault">Summer Semester 2018 - All Courses</TD>
</TR>
<TR>
<TD CLASS="pldefault">
<INPUT TYPE="radio" NAME="validterm" VALUE="201820 - S6" CHECKED>
<TD CLASS="pldefault">Summer Semester 2018 - First 6-week Summer Session</TD>
</TR>
<TR>
<TD CLASS="pldefault">
<INPUT TYPE="radio" NAME="validterm" VALUE="201820 - S62" CHECKED>
<TD CLASS="pldefault">Summer Semester 2018 - Second 6-week Summer Session</TD>
</TR>
<TR>
<TD CLASS="pldefault">
<INPUT TYPE="radio" NAME="validterm" VALUE="201820 - S8" CHECKED>
<TD CLASS="pldefault">Summer Semester 2018 - 8-week Summer Session</TD>
</TR>
<TR>
<TD CLASS="pldefault">
<INPUT TYPE="radio" NAME="validterm" VALUE="201830" CHECKED>
<TD CLASS="pldefault">Fall Semester 2018</TD>
</TR>
<TR>
<TD CLASS="pldefault">
<INPUT TYPE="radio" NAME="validterm" VALUE="201910" CHECKED>
<TD CLASS="pldefault">Spring Semester 2019</TD>
</TR>
</SELECT>
<BR>
<TR>
<TD CLASS="pldefault"> </TD>
</TR>
<TR>
<TD CLASS="pldefault">Subject:</TD>
<TD CLASS="pldefault">
<SELECT NAME="subjcode">
<OPTION VALUE="ALL">All Subjects
<OPTION VALUE="ANTH">Anthropology
<OPTION VALUE="BEST">Bio Engin Small Scale Tech
<OPTION VALUE="BIOE">Bioengineering
<OPTION VALUE="BIO">Biological Sciences
<OPTION VALUE="CHEM">Chemistry
<OPTION VALUE="CCST">Chicano Chicana Studies
<OPTION VALUE="CHN">Chinese
<OPTION VALUE="COGS">Cognitive Science
<OPTION VALUE="CRS">Community Research and Service
<OPTION VALUE="CSE">Computer Science & Engineering
<OPTION VALUE="CORE">Core
<OPTION VALUE="CRES">Critical Race & Ethnic Studies
<OPTION VALUE="ESS">Earth Systems Science
<OPTION VALUE="ECON">Economics
<OPTION VALUE="EDUC">Education
<OPTION VALUE="EECS">Elect. Engr. & Comp. Sci.
<OPTION VALUE="ENGR">Engineering
<OPTION VALUE="ENG">English
<OPTION VALUE="ENVE">Environmental Engineering
<OPTION VALUE="ES">Environmental Systems (GR)
<OPTION VALUE="FRE">French
<OPTION VALUE="GEOG">Geography
<OPTION VALUE="GASP">Global Arts Studies Program
<OPTION VALUE="HIST">History
<OPTION VALUE="HBIO">Human Biology
<OPTION VALUE="IH">Interdisciplinary Humanities
<OPTION VALUE="JPN">Japanese
<OPTION VALUE="MGMT">Management
<OPTION VALUE="MBSE">Materials & BioMat Sci & Engr
<OPTION VALUE="MSE">Materials Science & Engr
<OPTION VALUE="MATH">Mathematics
<OPTION VALUE="ME">Mechanical Engineering
<OPTION VALUE="MIST">Mgmt of Innov, Sust, and Tech
<OPTION VALUE="NSUS">Nat Sciences Undergrad Studies
<OPTION VALUE="NSED">Natural Sciences Education
<OPTION VALUE="PHIL">Philosophy
<OPTION VALUE="PHYS">Physics
<OPTION VALUE="POLI">Political Science
<OPTION VALUE="PSY">Psychology
<OPTION VALUE="PH">Public Health
<OPTION VALUE="PUBP">Public Policy
<OPTION VALUE="QSB">Quantitative & Systems Biology
<OPTION VALUE="SCS">Social Sciences
<OPTION VALUE="SOC">Sociology
<OPTION VALUE="SPAN">Spanish
<OPTION VALUE="SPRK">Spark
<OPTION VALUE="USTU">Undergraduate Studies
<OPTION VALUE="WCH">World Cultures & History
<OPTION VALUE="WH">World Heritage
<OPTION VALUE="WRI">Writing
</SELECT>
</TR>
<TR>
<TD CLASS="pldefault">
<INPUT TYPE="radio" NAME="openclasses" VALUE="Y" CHECKED>
<TD CLASS="pldefault">Open Classes Only</TD>
</TR>
<TR>
<TD CLASS="pldefault">
<INPUT TYPE="radio" NAME="openclasses" VALUE="N">
<TD CLASS="pldefault">All Classes</TD>
</TR>
</TABLE>
<BR>
<BR>
<INPUT TYPE="submit" VALUE="View Class Schedule">
</FORM>
<!-- ** START OF twbkwbis.P_CloseDoc ** -->
<TABLE CLASS="plaintable" SUMMARY="This is table displays line separator at end of the page."
WIDTH="100%" cellSpacing=0 cellPadding=0 border=0><TR><TD class="bgtabon" width="100%" colSpan=2><IMG SRC="/wtlgifs/web_transparent.gif" ALT="Transparent Image" CLASS="headerImg" TITLE="Transparent Image" NAME="web_transparent" HSPACE=0 VSPACE=0 BORDER=0 HEIGHT=3 WIDTH=10></TD></TR></TABLE>
Skip to top of page
</DIV>
<DIV class="footerbeforediv">
</DIV>
<DIV class="footerafterdiv">
</DIV>
<DIV class="globalafterdiv">
</DIV>
<DIV class="globalfooterdiv">
</DIV>
<DIV class="pagefooterdiv">
<SPAN class="releasetext">Release: 7.3 - Developed by UCM SIS</SPAN>
</DIV>
<DIV class="poweredbydiv">
</DIV>
<DIV class="div1"></DIV>
<DIV class="div2"></DIV>
<DIV class="div3"></DIV>
<DIV class="div4"></DIV>
<DIV class="div5"></DIV>
<DIV class="div6"></DIV>
<div class="banner_copyright"> <br><h5>© 2019 Ellucian Company L.P. and its affiliates.<br></h5></div>
</BODY>
</HTML>
Sorry for the lengthy question, hopefully I can pay it back to the community one day :)
I am a bit out of sync with web programming and getting into HTMLUnit
is a bit more confusing than I thought it would be.
If you like to automate web page these days you need a basic understanding of web technologies at least Html, Javascript and HTTP itself to be able to figure out what to do.
Lets start at the top - with your
lovely error
As a starting point open the page with a real browser and have a look at the web console. You will see the same error there; that means the page you are trying to automate has an error (at least one) and your browser simply ignores this.
HtmlUnit was created as a test tool; because of this it is more picky about errors. You have to disable this.
webClient.getOptions().setThrowExceptionOnScriptError(false);
Next step:
You are trying to access the form on the page
<FORM ACTION="xhwschedule.P_ViewSchedule" METHOD="post">
As the method name implies 'getFormByName()' is able to find forms having the right name attribute - but your form does not have one.
Next step:
<INPUT TYPE="radio" NAME="validterm" VALUE="201910" CHECKED>
As the method name implies 'getElementById("201910")' is able to find elements having the right id attribute - but your radio button does not have one.
And the same for the button.
Below you can find a quick hack that does the work. It might help to read at least the HtmlUnit - Getting Started with HtmlUnit page. There is also the javadoc available with detailed descriptions.
Hope that helps
public static void main(String[] args) throws IOException {
String url = "https://mystudentrecord.ucmerced.edu/pls/PROD/xhwschedule.p_selectsubject";
try (final WebClient webClient = new WebClient()) {
webClient.getOptions().setThrowExceptionOnScriptError(false);
HtmlPage page = webClient.getPage(url);
webClient.waitForBackgroundJavaScript(1000);
page = (HtmlPage) webClient.getCurrentWindow().getEnclosedPage();
final HtmlForm form = page.getForms().get(0);
for (DomElement elem : form.getElementsByTagName("INPUT")) {
if (elem instanceof HtmlRadioButtonInput) {
HtmlRadioButtonInput radioButton = (HtmlRadioButtonInput) elem;
if ("201910".equals(radioButton.getValueAttribute())
|| "N".equals(radioButton.getValueAttribute())) {
radioButton.setChecked(true);
}
}
}
for (DomElement elem : form.getElementsByTagName("INPUT")) {
if (elem instanceof HtmlSubmitInput) {
if ("View Class Schedule".equals(elem.getAttribute("value"))) {
elem.click();
}
}
}
webClient.waitForBackgroundJavaScript(1000);
page = (HtmlPage) webClient.getCurrentWindow().getEnclosedPage();
System.out.println("----------------");
System.out.println(page.asXml());
}
}

text field name should be unique

I am working on a project where the client's requirement is to add a dynamic text box. I made the dynamic text box but I'm not getting the unique name of the text box.
Here is my code:
<script type="text/javascript">
function addfieldset() {
var namefieldset = document.getElementById("name").cloneNode(true);
document.getElementById("names").appendChild(namefieldset);
}
function deletefieldset(e) {
var namefieldset = e.parentNode;
namefieldset.parentNode.removeChild(namefieldset);
}
</script>
<body>
<%! public static int i = 1;%>
<% if (i > 0) { %>
<div id="names"><div id="name"><% out.print(i);%>Name: <input name="namefield<%= i%>" type="text"/>delete</div></div>
<input id="addnamebtn" type="button" value="Add Name" onclick="addfieldset()"/>
<% i++;
}%>
</body>
You are mixing two different codes. The key is to realize, where and when each code is executed - JSP on the server when the page is requested and rendered (i.e. before the response is sent to the browser) and Javascript in the browser, after the browser receives the already generated response.
I.e. you have to change the name of the new text field in the addfieldset() function (which means you have to have a counter, how many text fields there already is).
The java code in scriptlet is executed on the server side. Hence, cloning it again through Javascript will not execute the scriptlet again.
An another approach of what you are trying to achieve will be to store the count variable in javascript.
var count = 1;
function addfieldset() {
count++;
var namefieldset = document.getElementById("name").cloneNode(true);
var textField = namefieldset.getElementsByTagName('input')[0];
textField.setAttribute("name", "namefield" + count);
textField.value = "";
document.getElementById("names").appendChild(namefieldset);
}
function deletefieldset(e) {
var namefieldset = e.parentNode;
namefieldset.parentNode.removeChild(namefieldset);
}
<body>
<div id="names">
<div id="name">
<span>Name:</span>
<input name="namefield1" type="text" />
delete
</div>
</div>
<input id="addnamebtn" type="button" value="Add Name" onclick="addfieldset()" />
</body>
try this JavaScript and HTML
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<script type="text/javascript">
var i = 0;
function generateRow() {
i++;
var d = document.getElementById("div");
d.name = "food";
d.innerHTML += "<p>name"+i+" :<input type='text' name='name" + i + "' /> <a href='#' onclick='deletefieldset(this)'>delete</a></p>";
}
function deletefieldset(e) {
var namefieldset = e.parentNode;
namefieldset.parentNode.removeChild(namefieldset);
}
function onLoad() {
generateRow();
}
window.onload = onLoad;
</script>
<body>
<div id="div"></div>
<p>
<input type="button" id="addnamebtn" value="Add Name" onclick="generateRow()" />
</p>
</body>
</html>

How to pass one JSP to another JSP?

I am creating small web apps and I am facing the following problem. I have 2 JSPs and when I click the submit button, it repeats the value every time. What I want is that when I click on the submit button it should give only the corresponding value.
index.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#page import="java.io.*,java.util.*" %>
<!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=ISO-8859-1">
<title>Class Video</title>
</head>
<body>
<form action="second.jsp" method="post">
<table>
<%
File f=new File("C:/Users/SHAKTI/Desktop/video");
File[] list=f.listFiles();
if(list.length!=0){
String s[]=new String[list.length];
for(int i=0;i<list.length;i++){
s[i]=list[i].toString();
String fi=list[i].getName();
%>
<tr><td><%=fi %></td>
<td><input type="text" name="file" value="<%=s[i] %>">
</td>
<td><input type="submit" name="play" value="Play"></td>
</tr>
<%}}
else{
%>
<tr>
<td>There is no any files in the database...</td>
</tr>
<%
}
%>
</table>
</form>
</body>
</html>
second.jsp
<form action="" method="post">
<%
response.setHeader("Cache-Control","no-cache");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", 0);
String id=request.getParameter("file");
out.println("id = "+id);
%>
<input type="submit" name="submit" value="submit>
</form>
First Jsp : Set Value in First Page
request.setAttribute("name",somevalue);
Second Jsp : Retrieve it in Second page
request.getAttribute("name")
use queryString
URl: http://myaddress.com/xyz?name=jill&sex=f
String someName = request.getParameter("name") ;
String sex = request.getParameter("sex") ;
One way is to use session as described by javaBeginner.
you can also create a from on the fly and submit it.
write a function similar to this one and use it in your success:
function submitValues(url, params) {
var form = [ '<form method="POST" action="', url, '">' ];
for(var key in params)
form.push('<input type="hidden" name="', key, '" value="', params[key], '"/>');
form.push('</form>');
jQuery(form.join('')).appendTo('body')[0].submit();
}
There are many options to pass a value from one jsp to another, Here are some
1) Adding that as a hidden variable and specifying the value
<input name="file" type="hidden" value=""/>
2)Adding it to the session and retrieving the session variable
session.setAttribute("file", value);
3)Passing that as a queryParameter
http://......one.jsp?file=""
It is beacause you are iterating the loop here,
for(int i=0;i<list.length;i++){
s[i]=list[i].toString();
String fi=list[i].getName();
so it will print the last element from the loop, to get the name u clicked on the button try this .. Change this line as
<input type="text" name="file" value="<%=s[i] %>">
as,
<td><input type="button" class="btn" data-reqno=value="<%=s[i] %>" value="file name">
And handle it using jQuery like this , so that you can pass the value to next JSP,
<script type="text/javascript">
$(document).ready(function () {
$(".btn").click(
function() {
var selectedFileName = $(this).attr("data-reqno");
var urlToApprove = "/yourApp/req/filename?name=" + selectedFileName;
}
);
});
</script>
And also try to avoid Scriptlets in JSP , you can use JSTL or El for the same purpose .
Hope it helps !!
there are many method to pass variable such as
session.setAttribute()
session.getAttribute
action "xxx.jsp?variable=1"

Submission of a jsp page after a particular time interval

I have used setTimeout method to do this and passed a variable which contains time but my settimeout method takes only the initialized value of that variable and not the value that is fetched from database.
Here is my code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Givetest</title>
<script type = "text/javascript">
function submitForm() {
document.forms[0].submit();
}
</script>
<script language="JavaScript" src="http://scripts.hashemian.com/js/countdown.js"></script>
</head>
<%
String ts=request.getParameter("testname");
session.setAttribute("tname", ts);
Connection con=null;
Statement s1=null;
Statement s=null;
ResultSet r1=null;
ResultSet r=null;
int t=120000;
String time=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:online_testing");
s=con.createStatement();
s1=con.createStatement();
r=s.executeQuery("select * from "+ts+"");
r1=s1.executeQuery("select duration from tests where testname="+ts+"");
if(r1.next())
{
time=r1.getString("duration");
t=Integer.parseInt(time)*60000;
logger.info(time);
}
else {
logger.info("No row found in db for test " + ts);
System.out.println("No row found in db for test " + ts);
out.println("<br>!! <b>No row found in db </b>for test " + ts + "<br><br><br>");
}
r1.close();
}
catch(Exception e1)
{
response.setContentType("text/html");
out.println(e1.toString());
}
%>
<body onload="setTimeout('submitForm()',<%=t%>)">
<div class="header"></div>
<div class="view" style="color: #050505">
<form action="Givetest" method="post">
<h1 align="center" style="color: #050505"><%=ts%></h1>
<%
int i=1;
while(r.next()){
String a = r.getString("question");
String b = r.getString("option1");
String c = r.getString("option2");
String d = r.getString("option3");
String e = r.getString("option4");
%>
Question <%=i%>:- <label> <%=a%></label><br>
<input type="radio" name="r<%=i%>" value="<%=b%>" checked><label><%=b%></label><br>
<input type="radio" name="r<%=i%>" value="<%=c%>"><label><%=c%></label><br>
<input type="radio" name="r<%=i%>" value="<%=d%>"><label><%=d%></label><br>
<input type="radio" name="r<%=i%>" value="<%=e%>"><label><%=e%></label><br>
<br>
<input type="hidden" name="h" value="<%=ts%>">
<%
i++;
}
r.close();
s.close();
con.close();
%>
<input type="submit" class="button">
</form>
</div>
<div class="copyright" align="center"> © SAUMYARAJ ZALA</div>
</body>
</html>
The mistake is in the where clause which should be like:-
r1=s1.executeQuery("select duration from tests where testname="+ts+"");
Moreover this code should be executed in servlets before it is passed to jsp
<body onload="setTimeout('submitForm()',<%=t%>)">
You are giving the value only once. DO you mean it gets value
int t=120000;
and not what is in data base? If so are you sure no error is being thrown?
By the way this is not the best way to write a web app - all in jsp - though it works, better is to make servlets and POJOs/ helper .java files for data base etc. Make sure your tomcat/ app server's temp folder are cleaned every time you restart - to make sure its taking latest jsp.
In jsp can have a text like 'Version 001' and increase that manually so your sure correct code version is running.
Use loggers or system.out.println if you do not have logger
r1=s1.executeQuery("select duration from tests where testname="+ts+"");
//if should be enough as you will only have 0 or 1 row per test?
if(r1.next())
{
time=r1.getString("duration");
t=Integer.parseInt(time)*60000;
} else{
logger.warn("No row found in db for test " + ts);
//okay for debug
out.println("<br>!! <b>No row found in db </b>for test " + ts + "<br><br><br>");
}
r1.close();
}
catch(Exception e1)
{
response.setContentType("text/html");
out.println("<br><br> <b> ERROR</b>" + e1.toString());
}
sql
testname="+ts+""
is very bad should use a prepared statement or you are asking for a SQL injection attack. look at owasp https://www.owasp.org/index.php/SQL_Injection_Prevention_Cheat_Sheet

Categories

Resources