get data from a table in a page with Java - java

I'm working in this project that opens a site pages fills the necesary fields get push the submit buttons and opens another window where some values are shown in a table, so far everything works ok but I don't know how to get the data from the table into my java program to save it in a file.
I'm working with Selenium WebDriver
this it's the code for my java program, I just need to get the info on the table:
import java.io.FileOutputStream;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.commons.exec.util.StringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
public class Know_Your_Case_Status {
public void FillData(WebDriver driver) throws InterruptedException {
for (int i = 1; i < 12; i++) {
driver.get("http://cms.nic.in/ncdrcusersWeb/login.do?method=caseStatus");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
//Select Radio Button for State Commission
driver.findElement(By.cssSelector("[id='UserType'][value='C']"))
.click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
// Now Select State Assam
WebElement SelectState = driver.findElement(By.name("state_id"));
Select Sl = new Select(SelectState);
Sl.selectByVisibleText("Assam");
/**** Select From Date ******/
driver.findElement(By.cssSelector("img.ui-datepicker-trigger"))
.click();
// Select may Month
Select SelMonth = new Select(driver.findElement(By
.className("ui-datepicker-month")));
SelMonth.selectByValue("4");
// Select Year 2015
Select SelYear = new Select(driver.findElement(By.id("scrollyear")));
SelYear.selectByVisibleText("2015");
// Select date 1
driver.findElement(By.linkText("1")).click();
/**** Select To Date ******/
// driver.findElement(By.cssSelector("img.ui-datepicker-trigger")).click();
driver.findElement(By.xpath("(//img[#alt='...'])[2]")).click();
// Select Jan Month
Select SelToMonth = new Select(driver.findElement(By
.className("ui-datepicker-month")));
SelToMonth.selectByVisibleText("January");
// Select Year 2016
Select SelToYear = new Select(driver.findElement(By
.id("scrollyear")));
SelToYear.selectByVisibleText("2016");
// Select date 1
driver.findElement(By.linkText("8")).click();
Select SelCaseType = new Select(driver.findElement(By
.name("condition")));
SelCaseType.selectByVisibleText("CaseType");
Select Selval = new Select(driver.findElement(By.name("ctId")));
Selval.selectByIndex(i+1);
//Selval.selectByValue("8");
driver.findElement(By.name("advs")).click();
}
}
}
And the code source from the page I'm trying to get the info it's:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Query Report</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="./stylesheet/confoStyle.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="javascript/CommonCDRC.js"></script>
<script language="javaScript">
function doPrint()
{
tbHead.style.display = "none";
tbTail1.style.display = "none";
tbTail2.style.display = "none";
tbMenu.style.display = "none";
window.print();
tbHead.style.display = "";
tbTail1.style.display = "";
tbTail2.style.display = "";
tbMenu.style.display = "";
}
function submitForm()
{
var flgSubmit = 1;
var dtOfHearing = document.loginForm.dtOfHearing.value;
if(flgSubmit == 1)
{
document.loginForm.method.value = "loadSelectloginForCLhtml";
document.loginForm.submit();
}
else
return false;
}
function loadProceeding(caseid, fano)
{
document.loginForm.fano.value=fano;
document.loginForm.cid.value=caseid;
document.loginForm.action="ViewProceedingCS.jsp";
document.loginForm.submit();
}
</script>
</head>
<body bgcolor="#9cd3ed">
<form name="loginForm" method="post" action="/ncdrcusersWeb/login.do" onsubmit="return submitForm()">
<input type="hidden" name="method" value="ViewProceedingCS">
<input type="hidden" name="fano" value="">
<input type="hidden" name="case_id_in" value="">
<input type="hidden" name="dtOfHearing" value="">
<input type="hidden" name="courtId" value="">
<input type="hidden" name="cid" value="">
<input type="hidden" name="stateCode" value="5">
<input type="hidden" name="distCode" value="0">
<table class="baseContaner topGroup" width="100%" align="center">
<tr>
<td width="3%" class="rptsubnumhd">SN</td>
<td width="10%" class="rptsubnumhd">Case No</td>
<td width="17%" class="rptsubtxthd">Complainant</td>
<td width="17%" class="rptsubtxthd">Respondent</td>
<td width="18%" class="rptsubtxthd">Complainant-Advocate</td>
<td width="17%" class="rptsubtxthd">Respondent-Advocate</td>
<td width="8%" class="rptsubnumhd">Date of Filing</td>
<td width="10%" class="rptsubnumhd">
Date of Next Hearing
</td>
</tr>
<tr>
<td class="rptnumhval">1</td>
<td class="rptnumhval"><a class="help" href="javascript:loadProceeding('5/0/A/19/2015','A/19/2015' )">
A/19/2015 </a></td>
<td class="rpttxthval">Managing Director, The Assam Power Distribution Company Ltd.</td>
<td class="rpttxthval">Smti Khaleda Begum</td>
<td class="rpttxthval">Mr. P. Bhowmick</td>
<td class="rpttxthval"></td>
<td class="rptnumhval">15/05/2015</td>
<td class="rptnumhval">
19/05/2015
</td>
</tr>
<tr>
<td class="rptnumhval">2</td>
<td class="rptnumhval"><a class="help" href="javascript:loadProceeding('5/0/A/20/2015','A/20/2015' )">
A/20/2015 </a></td>
<td class="rpttxthval">The Chief Regional Manager, United India Insurance Company Ltd.</td>
<td class="rpttxthval">Mr. Dulu Dey</td>
<td class="rpttxthval">Mr. R. Goswami</td>
<td class="rpttxthval"></td>
<td class="rptnumhval">20/05/2015</td>
<td class="rptnumhval">
26/05/2015
</td>
</tr>
<tr>
<td class="rptnumhval">3</td>
<td class="rptnumhval"><a class="help" href="javascript:loadProceeding('5/0/A/21/2015','A/21/2015' )">
A/21/2015 </a></td>
<td class="rpttxthval">Dr. Vijay Nahata</td>
<td class="rpttxthval">Smti. Moushumi Nath</td>
<td class="rpttxthval">Mr. N. Sharma</td>
<td class="rpttxthval">Ms. D. Tamuli</td>
<td class="rptnumhval">05/06/2015</td>
<td class="rptnumhval">
11/09/2015
</td>
</tr>
<tr>
<td class="rptnumhval">4</td>
<td class="rptnumhval"><a class="help" href="javascript:loadProceeding('5/0/A/22/2015','A/22/2015' )">
A/22/2015 </a></td>
<td class="rpttxthval">Sri Biren Kalita</td>
<td class="rpttxthval">The Branch Manager, Ulubari Branch (CDO-II), Oriental Insurance Co. Ltd.</td>
<td class="rpttxthval">Mr. A. K. Gupta</td>
<td class="rpttxthval">Mr. S. Bhuyan</td>
<td class="rptnumhval">15/06/2015</td>
<td class="rptnumhval">
21/09/2015
</td>
</tr>
<tr>
<td class="rptnumhval">5</td>
<td class="rptnumhval"><a class="help" href="javascript:loadProceeding('5/0/A/23/2015','A/23/2015' )">
A/23/2015 </a></td>
<td class="rpttxthval">Smti. Sabita Roy</td>
<td class="rpttxthval">Managing Director, Birla Sun Life Insurance Co. Ltd.</td>
<td class="rpttxthval">Mr. N. N. Karmakar</td>
<td class="rpttxthval"></td>
<td class="rptnumhval">15/06/2015</td>
<td class="rptnumhval">
07/09/2015
</td>
</tr>
<tr>
<td class="rptnumhval">6</td>
<td class="rptnumhval"><a class="help" href="javascript:loadProceeding('5/0/A/24/2015','A/24/2015' )">
A/24/2015 </a></td>
<td class="rpttxthval">Branch Manager, Indian Overseas Bank</td>
<td class="rpttxthval">Mr. Padmeswar Baruati</td>
<td class="rpttxthval">Mr. V.K.Dewan</td>
<td class="rpttxthval"></td>
<td class="rptnumhval">24/06/2015</td>
<td class="rptnumhval">
17/09/2015
</td>
</tr>
<tr>
<td class="topHdMsg" colspan="8"><input type=button value="Back" onClick="history.go(-1)"></td>
</tr>
</table>
</form>
</body>
</html>
I was thinking that maybe a driver.findElement(By.tagName("table")).getText() may work but I'm getting all the data in one line, is it a way to separete the head and the lines ?

You should try as below :-
List<WebElement> rows = driver.findElement(By.tagName("table")).findElements(By.tagName("tr"));
for(WebElement row : rows)
{
List<WebElement> columns = row.findElements(By.tagName("td"));
for(WebElement column : columns)
{
String columnText = column.getText();
}
}
Hope it helps...:)

Related

How to get the last row number of table which is dynamically updating?

How we can get the Table(in a webpage) row using the value it contain.
Suppose a table of 3*3. In that cell(2,3) cell text is "Test". So how to find the row number = 2 using the the cell text "Test".
Selenium-2.53.1
Java-8
This is the xpath
//table[2]/tbody/tr/td[2]/table[2]/tbody/tr[7]/td/div[2]/table/tbody/tr[1]/td[1]/div/a/font
in which bolded tr (here tr[1]) is the row I want to change dynamically & the text is inside the bolded td (here td[1])
My html code is :
<html>
<head></head>
<body>
<form name="fm" method="post">
<table>
<!-- --Some data--- -->
</table>
<table width="100%" height="100%" border="0" >
<tr valign="top" >
<td width="200" height="100%" rowspan="3" align="center" >
<p></p>
<table width="89%" height="270" border="0">
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<!-- --Some data--- -->
<tr></tr>
<tr></tr>
<tr></tr>
<tr>
<td><table width="100%" height="71" border="0" align="right">
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
</table></td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<!-- --Some data--- -->
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
</table>
<p></p>
</td>
<td width="622" height="30" colspan="3" align="left" valign="top">
<table width="100%" height="40" align="center">
<tr><!-- --Some data--- --></tr>
</table>
<table width="476" height="110" align="center">
<tr></tr>
<tr></tr>
<tr></tr>
<!-- --Some data--- -->
<tr></tr>
<tr></tr>
<tr></tr>
<tr>
<td height="22" colspan="3">
<div align="left">
<table width="469" border="1">
<tr bgcolor="#006291">
<td width="81" bgcolor="#006291"><div align="center">SlNo.</div></td>
<td width="82" bgcolor="#006291"><div align="center">Code</div></td>
<td width="300" bgcolor="#006291"><div align="center">Name</div></td>
</tr>
</table>
</div>
<div align="left" style="width:465px;Height:150px;">
<table width="465" bgcolor="#FFFFFF" border="1">
<tr bordercolor="#006291" bgcolor='#FFEADF' >
<td width="81" height='5' valign="top"><div align="center"><font color="#006291" size="3" >1</font></div></td>
<td width="81" height='5' valign="top"><div align="center"><font color="#006291" size="3" >01</font></div></td>
<td width="300" height='5' valign="top"><div align="center"><font color="#006291" size="3" >tvm1</font></div></td>
</tr>
<tr bordercolor="#006291" bgcolor='#F1F8FC' >
<td width="81" height='5' valign="top"><div align="center"><font color="#006291" size="3" >2</font></div></td>
<td width="81" height='5' valign="top"><div align="center"><font color="#006291" size="3" >02</font></div></td>
<td width="300" height='5' valign="top"><div align="center"><font color="#006291" size="3" >tvm2</font></div></td>
</tr>
<tr bordercolor="#006291" bgcolor='#FFEADF' >
<td width="81" height='5' valign="top"><div align="center"><font color="#006291" size="3" >3</font></div></td>
<td width="81" height='5' valign="top"><div align="center"><font color="#006291" size="3" >03</font></div></td>
<td width="300" height='5' valign="top"><div align="center"><font color="#006291" size="3" >tvm3</font></div></td>
</tr>
<tr bordercolor="#006291" bgcolor='#F1F8FC' >
<td width="81" height='5' valign="top"><div align="center"><font color="#006291" size="3" >4</font></div></td>
<td width="81" height='5' valign="top"><div align="center"><font color="#006291" size="3" >04</font></div></td>
<td width="300" height='5' valign="top"><div align="center"><font color="#006291" size="3" >tvm4</font></div></td>
</tr>
<tr bordercolor="#006291" bgcolor='#FFEADF' >
<td width="81" height='5' valign="top"><div align="center"><font color="#006291" size="3" >5</font></div></td>
<td width="81" height='5' valign="top"><div align="center"><font color="#006291" size="3" >10</font></div></td>
<td width="300" height='5' valign="top"><div align="center"><font color="#006291" size="3" >tvm5</font></div></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
"count(//table[#id='tableid']//td[.='Test']/parent::tr/preceding-sibling::tr) + 1"
put in your own table identifier... depends on it being a simple table without rowspans and colspans.
I tried capturing the column data of all rows into a List(observe the xpath of 'rowList' below, no number given for the final 'tr' which gets the column data for all rows), and using foreach got the index of the row which contains required text.
Will have to change the value in 'expRowValue' to have it worked with different data.
public class Table {
WebDriver driver;
By rowList = By.xpath("html/body/div[1]/table/tbody/tr/td[2]/table/tbody/tr[4]/td/table/tbody/tr/td[2]/table/tbody/tr[2]/td[1]/table[1]/tbody/tr[3]/td/table/tbody/tr/td[2]");
#Test
public void f() {
String expRowValue="$513";
System.setProperty("webdriver.chrome.driver", "C:/Users/dell/Downloads/chromedriver/chromedriver.exe");
driver = new ChromeDriver();
driver.get("http://newtours.demoaut.com/");
driver.manage().window().maximize();
List<WebElement>rowsData = driver.findElements(rowList);
int k=1;
for (WebElement rowValue: rowsData) {
if (rowValue.getText().equals(expRowValue)){
System.out.println("ROw Index::" + k);
}
k++;
}
}
}
If you want to click on <td> on the basis of text try below xpath :-
.//td[child::a/font[text() = 'your text hare']]
Or if you to click on <a> inside <td> on the basis of text try below xpath :-
.//td/a[child::font[text() = 'your text hare']]
Or it you want to click on table cell using their row and column index follow this link

input map value into another map name in jsp page

I want to generate tables in jsp page using data I got from Map in java. I use which use map value for define 'item'. But, The name of map value that I want to put on 'item' needs value from another map.
To be clear, here my jsp code;
<c:forEach var="wilayahProvinsi" items="${model.kodeKabupatenList}">
<div data-role="page" id="kode${wilayahProvinsi.ID2012}">
<div data-role="header" data-position="inline" data-fullscreen="true">
Back
<h1>${wilayahProvinsi.NAMA}</h1>
</div>
<div class="container">
<table id="example1" class="display nowrap" >
<thead>
<tr>
<th>Kode Komoditas</th>
<th>Jenis Barang</th>
<th>Nilai Konsumsi</th>
<th>Nilai Imputasi</th>
<th>Nilai Konsumsi Akhir</th>
<th>Persentase trhdp Total</th>
<th>Persentase trhdp Kelompok</th>
<th>Persentase trhdp Subkelompok</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<tbody>
<!-- this is the problem -->
<c:forEach var="pekerjaanku" items="${model.pekerjaankuList$wilayahProvinsi.ID2012}">
<tr>
<td>${pekerjaanku.kode_komoditas}</td>
<td id="jenis_barang">${pekerjaanku.jenis_barang}</td>
<td style="text-align: right">${pekerjaanku.nilai_konsumsi}</td>
<td style="text-align: right">${pekerjaanku.nilai_imputasi}</td>
<td style="text-align: right">${pekerjaanku.nilai_konsumsi_akhir}</td>
<td style="text-align: right">${pekerjaanku.persentase_total}</td>
<td style="text-align: right">${pekerjaanku.persentase_kelompok}</td>
<td style="text-align: right">${pekerjaanku.persentase_subkelompok}</td>
<td><a href="kotaEdit?id=${pekerjaanku.kode_komoditas}" class="ui-btn ui-mini ui-corner-all ui-icon-edit
ui-btn-icon-left">Edit</a></td>
<td><a href="kotaDelete?id=${pekerjaanku.kode_komoditas}" class="ui-btn ui-mini ui-corner-all ui-icon-delete
ui-btn-icon-left" onclick="return confirm('Yakin ingin menghapus komoditas ${pekerjaanku.jenis_barang}?')">
Delete</a></td>
</tr>
</c:forEach>
</tbody>
</table>
<table>
<tr>
<td colspan="8">Tambah Komoditas Baru</td>
<td colspan="2">Download CSV</td>
</tr>
</table>
</div>
</div>
</c:forEach>
This is my Java code;
#RequestMapping("/jelajahPekerjaanKota")
public ModelAndView getPekerjaanKotaList() {
List<KodeKabupaten> kodeKabupatenList = usersService.getSpecifiedKodeKabupatenList();
Map<String, Object> model = new HashMap<String, Object>();
model.put("kodeKabupatenList", kodeKabupatenList);
for(KodeKabupaten kodeKabupaten : kodeKabupatenList){
model.put("pekerjaankuList" + kodeKabupaten.getID2012(), pekerjaankuService.getPekerjaankuList(kodeKabupaten.getID2012()));
}
return new ModelAndView("/provinsi/jelajahPekerjaanKota", "model", model);
}
To be clear, the objects in Map model is;
model.kodeKabupatenList which has attributes: NAMA, ID2012, PROV, and KAB
model.pekerjaankuList3171 which has attributes: kode_komoditas, jenis_barang, ...
model.pekerjaankuList3172 , the attributes are same with above
model.pekerjaankuList3173 , same with above
my problem is how to get all model.pekerjaankuList** in jsp with looping? I can not run this code in jsp;
<c:forEach var="pekerjaanku" items="${model.pekerjaankuList$wilayahProvinsi.ID2012}">

Not able to read an url content in Java

URL oracle = new URL("hurlAddress/dinfo.cgi");
BufferedReader in = new BufferedReader(
new InputStreamReader(oracle.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
I get
<html>
<head>
<!-- RUI RC=100 -->
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>Don't open this page!</title>
</head>
<body bgcolor="#C0C0C0">
<center>
<table border="0" cellpadding="0" cellspacing="4" width="400">
<tr><td align="center" valign="top" width="48">
<img src="en/media/ss_wrn.gif" border="0" width=32 height=32>
</td>
<td>
<font size="4" face="Helvetica,Arial">
<b>User information is disabled.</b><br>
This operation cannot be accepted. User certification is invalid or date expired.<br>
Update page.<br>
</font>
</td>
</tr>
<tr><td></td>
<td align="right">
<img src="en/media/b_ok.gif" border="0" alt="OK" title="OK">
</td>
</tr>
</table>
</center>
</body>
I was expecting
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>Remote UI:Device Information</title>
</head>
<body bgcolor="white" link="blue" alink="red" vlink="blue">
<a name="page_top"></a>
<form>
<SCRIPT LANGUAGE="JavaScript">
var has_fax = false; // true or false
var Fax_Type = "0"; // 0(None),1(PSTN),2(PSTNx2),3(ISDN)
var has_send =true; // has send
var is_oem = false;
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
function reload_device(){
var cgi_str = "./dinfo.cgi?";
// for Expire Cache!!
var now_time = new Date();
cgi_str += "Dummy=" + now_time.getTime();
document.location.href = cgi_str;
}
</SCRIPT>
<table border="0" cellpadding="0" cellspacing="2" width="100%">
<tr>
<td valign="middle"><font size="4" color="#000066"><b><table border="0" cellpadding="0" cellspacing="2">
<tr>
<td rowspan="2" nowrap><img src="en/media/imgs030.gif"></td>
<td nowrap><font face="Helvetica,Arial" size="4" color="#000066"><b>slq29986</b></font></td>
</tr>
<tr>
<td nowrap><font size="2">iR5570</font></td>
</tr>
</table></b></font></td>
<td valign="middle" width="70" align="right"><font size="4" color="black"><b><img src="en/media/bh_updt.gif" width="28" height="28" border="0" alt="Update" title="Update"></b></font></td>
</tr>
</table>
<hr noshade size="2">
<table border="0" cellpadding="0" cellspacing="4" width="100%">
<tr>
<td align="left"><font size="1"> Last Updated :05/26/2016 19:30:54</font></td>
</tr>
</table><table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr height="26">
<td bgcolor="#000066" height="26"><font color="white" face="Helvetica,Arial"><b> Device Information</b></font></td>
</tr>
</table><table border="0" cellspacing="2" cellpadding="2" width="100%">
<SCRIPT LANGUAGE="JavaScript">
if(is_oem == false)
{
document.write('<tr>');
document.write('<td width="3%"></td>');
document.write('<td width="40%"><font face="Helvetica,Arial" size="2">Manufacturer :</font></td>');
document.write('<td><font size="4">CANON INC</font></td>');
document.write('</tr>');
}
</SCRIPT>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Device Name :</font></td>
<td><font size="4">slq29986</font></td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Location :</font></td>
<td><font size="4">MESAAS</font></td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Product Name : </font></td>
<td>iR5570</td>
</tr>
<tr>
<td colspan="3"><hr size="1"></td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Serial Number :</font></td>
<td>SLQ29986</td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Main Board Version :</font></td>
<td>1</td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Controller Version :</font></td>
<td>3604.838.3201</td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Scanner Version :</font></td>
<td>401.100</td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Finisher Version :</font></td>
<td>801</td>
</tr>
<SCRIPT LANGUAGE="JavaScript">
if(has_send == true)
{
document.write('<tr>');
document.write('<td colspan="3">');
document.write('<hr size="1">');
document.write('</td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td width="3%"></td>');
document.write('<td width="40%"><font face="Helvetica,Arial" size="2">Receive E-mail Address :</font></td>');
document.write('<td>aaa#aaa.edu</td>');
document.write('</tr>');
}
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
if( has_fax == true )
{
document.write('<tr>');
document.write('<td colspan="3">');
document.write('<hr size="1">');
document.write('</td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td width="3%"></td>');
document.write('<td width="40%"><font face="Helvetica,Arial" size="2">Telephone Number :</font></td>');
document.write('<td></td>');
document.write('</tr>');
if( Fax_Type == "3" )
{
document.write('<tr>');
document.write('<td width="3%"></td>');
document.write('<td width="40%"><font face="Helvetica,Arial" size="2">Subaddress :</font></td>');
document.write('<td></td>');
document.write('</tr>');
}
}
</SCRIPT>
<tr>
<td colspan="3">
<hr size="1">
</td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">System Manager :</font></td>
<td>MESAAS</td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Contact Information :</font></td>
<td></td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">E-mail Address :</font></td>
<td></td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Support :</font></td>
<td></td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Administrator Comment (E-mail) :</font></td>
<td></td>
</tr>
<tr>
<td colspan="3">
<hr size="1">
</td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Contact Person :</font></td>
<td></td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Phone :</font></td>
<td></td>
</tr>
<tr>
<td width="3%"></td>
<td width="40%"><font face="Helvetica,Arial" size="2">Comment (E-mail) :</font></td>
<td></td>
</tr>
</table>
<p>
<hr size="2">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td valign="bottom"><img src="en/media/ba_ptp.gif" border="0" hspace="2" vspace="2" alt="Back to the Top on This Page" title="Back to the Top on This Page"></td>
</tr>
</table>
</form>
</body>
</html>
Thanks to amitmah and Gilbert Le Blanc I installed
httpfox addon on firefox and I noticed that I need to set a cookie
URL url = new URL("urlAddress/dinfo.cgi");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestProperty("Cookie", "iR=7472571");
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))){
StringBuilder builder = new StringBuilder();
int cp;
while ((cp = in.read()) != -1) {
builder.append((char) cp);
}
return builder.toString();
}
In browser this cookie is set if I access first urlAddress. If I tried to access directly urlAddress/dinfo.cgi I get the same "User information is disabled..." response.

how the solve the error Operation not allowed after ResultSet closed

I try to execute this code it will show the following error:
java.sql.SQLException.Operation not allowed after ResultSet closed
This is my code.in this code itself shows the above error..
<table cellspacing="0">
<%
try{
ResultSet rs1=st.executeQuery("select u.post_id,u.userid,u.post_txt from requestdetails as r inner join user_post as u on r.frdname=u.userid where r.userid='"+id+"'");
while(rs1.next()){
int post_id=rs1.getInt(1);
int fid=rs1.getInt(2);
System.out.println("iiii "+fid);
String text=rs1.getString(3);
System.out.println("txttt "+text);
ResultSet rs3=stat.executeQuery("select * from userdetails where userid='"+fid+"'");
if(rs3.next()){
String na=rs3.getString("username");
System.out.println("username "+na);
String img=rs3.getString("profilepic");
System.out.println("imgee "+img);
%>
<tr>
<td width="5%" style="padding-left:25;" rowspan="2"> <img src="images/<%=img%>" height="60" width="55"> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="3" style="padding:7;"><%=rs3.getString("username") %> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td></td>
<td colspan="3" style="padding-left:7;"><%=text %></td>
</tr>
<%
ResultSet rr=st.executeQuery("select * from comment_status where post_id='"+post_id+"'");
while(rr.next()){
int uid=rr.getInt("userid");
String cmt=rr.getString("comment");
ResultSet rrr=stat.executeQuery("select * from userdetails where userid='"+uid+"'");
if(rrr.next()){
%>
<tr>
<td> </td>
<td width="4%" bgcolor="#EDEFF4" style="padding-left:12;" rowspan="2"> <img src="" height="40" width="47"> </td>
<td bgcolor="#EDEFF4" style="padding-left:7;" > <%=rrr.getString("username") %> </td>
<td align="right" rowspan="2" bgcolor="#EDEFF4">
</tr>
<tr>
<td> </td>
<td bgcolor="#EDEFF4" style="padding-left:7;" colspan="2"><%=cmt %></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<%
}
}
%>
<tr>
<td> </td>
<td width="4%" style="padding-left:17;" bgcolor="#EDEFF4" rowspan="2"> <img src="images/" height="33" width="33"> </td>
<td bgcolor="#EDEFF4" colspan="2" style="padding-top:15;">
<form method="post" name="commenting" onSubmit="return blank_comment_check()" action="commentstatus.jsp">
<input type="text" name="comment_txt" placeholder="Write a comment..." maxlength="420" style="width:100px;" id="">
<input type="hidden" name="postid" value="<%=post_id%>">
<input type="hidden" name="userid" value="">
<input type="submit" name="comment" style="display:none;">
</form>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="4"align="right" style="border-top:outset; border-top-width:thin;"> </td>
</tr>
<%
}
}
}catch(Exception e){
e.printStackTrace();
}
%>
</table>
</div>
I don't know what mistake I've done in above code.
After I change the code like this, it's working fine...
Statement stt=con.createStatement();
ResultSet rs1=stt.executeQuery("select u.post_id,u.userid,u.post_txt from requestdetails as r inner join user_post as u on r.frdname=u.userid where r.userid='"+id+"'");
while(rs1.next()){
int post_id=rs1.getInt(1);
int fid=rs1.getInt(2);
System.out.println("iiii "+fid);
String text=rs1.getString(3);
System.out.println("txttt "+text);
Statement st1=con.createStatement();
ResultSet rs3=st1.executeQuery("select * from userdetails where userid='"+fid+"'");
if(rs3.next()){
String na=rs3.getString("username");
System.out.println("username "+na);
String img=rs3.getString("profilepic");
System.out.println("imgee "+img);
I made the mistake of using the same statement for all queries.
When I created different statements object for the solution it works fine.

How to do validation in java script involve two jsp page?

First page's image
Second page's image
First page's code
<jsp:useBean id="labelBean" scope="session"
class="my.com.infopro.ibank.ui.bean.LabelBean" />
<jsp:useBean id="txLimitMaintBean" scope="session"
class="my.com.infopro.ibank.ui.bean.TxLimitMaintBean" />
<jsp:useBean id="lang" scope="session"
class="my.com.infopro.ibank.ui.bean.LanguageBean" />
<%# page import="java.util.Iterator"%>
<%# page import="my.com.infopro.ibank.dto.TxLimitMaintDto"%>
<%# page import="my.com.infopro.ibank.ui.bean.TxLimitMaintBean"%>
<%
request.getSession(true);
String contextPath = request.getContextPath();
txLimitMaintBean.queryTxList();
//String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>
<%
labelBean.getLabel("TRANSACTION_LIMIT");
%>
</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">
<jsp:include page="/ScriptHeader.jsp"/>
</head>
<body>
<form name="form" method="POST" action="" dir="<%=lang.getDir()%>">
<table width="500" border="0" align="center">
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td colspan="4">
<p align="left" class="mainHeader"><%=labelBean.getLabel("TRANSACTION_LIMIT")%>
</p>
</td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td colspan="4">
<p align="left" class="subHeader"><%=labelBean.getLabel("CURR_TRNSCT_LMT")%></p>
</td>
</tr>
<tr>
<td colspan="3"><div align="center">
<p class="statusError">
<%if(request.getParameter("error") != null) out.println(labelBean.getLabel(request.getParameter("error"))); else out.println("");%>
</p>
</div></td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td colspan="4">
<p align="left"><%=labelBean.getLabel("FILL_IN_NEWLMT")%></p>
</td>
</tr>
<tr>
<td colspan="4">
<p align="left"><%=labelBean.getLabel("MAX_LMT")%></p>
</td>
</tr>
</table>
<br />
<table align="center">
<tr class="table_header">
<td width="130" align="left" class="tableHeader"><%=labelBean.getLabel("LIMIT")%></td>
<td width="130" align="left" class="tableHeader"><%=labelBean.getLabel("EXISTING_LIMIT")%></td>
<td width="130" align="right" class="tableHeader"><%=labelBean.getLabel("MAX_LIMIT")%></td>
<td width="80" align="left" class="tableHeader"></td>
</tr>
<%
for (Iterator iter = txLimitMaintBean.getTxLimitMaintList().iterator(); iter
.hasNext();) {
TxLimitMaintDto txLimitMaintDto = (TxLimitMaintDto) iter.next();
%>
<tr class="tableRowEven">
<td><%=txLimitMaintDto.getTxType()%></td>
<td><%=txLimitMaintDto.getTxCurrLimit()%></td>
<td><%=txLimitMaintDto.getTxMaxLimit()%></td>
<td><%=labelBean.getLabel("UPDATE")%> </td>
</tr>
<%
}
%>
</table>
<br />
<br />
<table width="500" border="0" align="center">
<tr>
<td align="left" class="footer"><%=labelBean.getLabel("DISCLAIMER")%></td>
</tr>
<tr>
<td align="left" class="footer">
<ul>
<li><%=labelBean.getLabel("TRANSFER_SUCCESS")%></li>
</ul>
</td>
</tr>
</table>
<jsp:include page="/Footer.jsp" />
</form>
</body>
</html>
Second page's code
<jsp:useBean id="labelBean" scope="session"
class="my.com.infopro.ibank.ui.bean.LabelBean" />
<jsp:useBean id="txLimitMaintBean" scope="session"
class="my.com.infopro.ibank.ui.bean.TxLimitMaintBean" />
<jsp:useBean id="lang" scope="session"
class="my.com.infopro.ibank.ui.bean.LanguageBean" />
<%# page import="java.util.Iterator"%>
<%# page import="my.com.infopro.ibank.dto.TxLimitMaintDto"%>
<%# page import="my.com.infopro.ibank.ui.bean.TxLimitMaintBean"%>
<%
//request.getSession(true);
String contextPath = request.getContextPath();
//String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>
<%
labelBean.getLabel("TRANSACTION_LIMIT");
%>
</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">
<jsp:include page="/ScriptHeader.jsp"/>
<script language="JavaScript">
function back() {
document.form.action="<%=contextPath %>/TxLimitMaintServlet?tranx=start";
document.form.submit();
}
function validateAndSubmit() {
var msg1 = "<%=labelBean.getLabel("MSG_REQUIRED_FIELD")%>";
var msg2 = "<%=labelBean.getLabel("MSG_CANNOT_CONTAIN_CHARACTER")%>";
var msg3 = "<%=labelBean.getLabel("MSG_IN_THE_FIELD")%>";
var msg4 = "<%=labelBean.getLabel("MSG_PLEASE_ENTER")%>";
var msg5 = "<%=labelBean.getLabel("WITH")%>";
var msg6 = "<%=labelBean.getLabel("TO")%>";
var msg7 = "<%=labelBean.getLabel("MSG_CHARACTER")%>";
var msg8 = "<%=labelBean.getLabel("MSG_PLEASE_ENTER_VALID_NUMBER")%>";
var msg9 = "<%=labelBean.getLabel("MSG_REQUIRED_FIELD")%>";
var msg10 = "<%=labelBean.getLabel("MSG_WITH_EXACTLY")%>";
var msg11 = "<%=labelBean.getLabel("MSG_WITH_VALID_DATE")%>";
var msg12 = "<%=labelBean.getLabel("MSG_EXAMPLE_DATE")%>";
var msgNum11 = "<%=labelBean.getLabel("MSG_WITH_A_MINIMUM_VALUE_OF")%>";
var msgNum12 = "<%=labelBean.getLabel("MSG_WITH_A_MAX_VALUE_OF")%>";
var msgNum13 = "<%=labelBean.getLabel("MSG_PLEASE_ENTER_ROUND_INETEGER")%>";
var msgNum14 = "<%=labelBean.getLabel("MSG_PLEASE_ENTER_AT_MOST")%>";
var msgNum15 = "<%=labelBean.getLabel("MSG_DECIMAL_PLACES")%>";
var maxLimit = parseInt(form.maxLimit.value);
var newLimit = parseInt(form.txNewLimit.value);
if (! validateNumericEntry(form.txNewLimit, "<%=labelBean.getLabel("NEW_LIMIT")%>" + " ", true, 2, 1, <%=TxLimitMaintBean.getTotalMaxLimit()%>, msg9, msg8, msg4,
msgNum11, msgNum12, msgNum13, msgNum14, msgNum15))
return false;
if( newLimit > maxLimit){
alert("<%=labelBean.getLabel("MSG_CANNOT_EXCEED")%>");
return false;
}
return true;
}
</script>
</head>
<body>
<form name="form" method="POST" action="<%=contextPath%>/TxLimitMaintServlet?tranx=confirm" onsubmit="#" dir="<%=lang.getDir()%>">
<table width="500" border="0" align="center">
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td colspan="4">
<p align="left" class="mainHeader"><%=labelBean.getLabel("TRANSACTION_LIMIT")%>
</p>
</td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td colspan="4">
<p align="left" class="subHeader"><%=labelBean.getLabel("CURR_TRNSCT_LMT")%></p>
</td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td colspan="4">
<p align="left"><%=labelBean.getLabel("FILL_IN_NEWLMT")%></p>
</td>
</tr>
<tr>
<td colspan="4">
<p align="left"><%=labelBean.getLabel("MAX_LMT")%></p>
</td>
</tr>
</table>
<br />
<table align="center">
<tr class="table_header">
<td width="130" align="left" class="tableHeader"><%=labelBean.getLabel("LIMIT")%></td>
<td width="130" align="left" class="tableHeader"><%=labelBean.getLabel("EXISTING_LIMIT")%></td>
<td width="130" align="left" class="tableHeader"><%=labelBean.getLabel("NEW_LIMIT")%></td>
<td width="80" align="right" class="tableHeader"><%=labelBean.getLabel("MAX_LIMIT")%></td>
</tr>
<tr class="tableRowEven">
<td><%=txLimitMaintBean.getTxType()%></td>
<td><input name="txCurrLimit" + type="text"
value="<%=txLimitMaintBean.getTxCurrLimit()%>" readonly="readonly"></td>
<td><input name="txNewLimit" type="text"></td>
<td><%=txLimitMaintBean.getTxMaxLimit()%></td>
<td><input name="maxLimit" value="<%=txLimitMaintBean.getTxMaxLimit()%>" type="hidden"></input></td>
</tr>
</table>
<br />
<table align="center">
<tr>
<td align="right"><input type="button" class="button" value="Back" onclick="back();"></td>
<td align="right"><input type="reset" class="button"
value="Reset"></td>
<td align="left"><input type="submit" class="button" value="Next"
onClick="return validateAndSubmit();"></td>
</tr>
</table>
<br />
<table width="500" border="0" align="center">
<tr>
<td align="left" class="footer"><%=labelBean.getLabel("DISCLAIMER")%></td>
</tr>
<tr>
<td align="left" class="footer">
<ul>
<li><%=labelBean.getLabel("TRANSFER_SUCCESS")%></li>
</ul>
</td>
</tr>
</table>
<jsp:include page="/Footer.jsp" />
</form>
</body>
</html>
The problem is: how can I validate add up of both 3rd Party Transfer and Bill Payment can not exceed 10,000?
you wouldn't be able to javascript to get the values from the previous page. any reason why you can't access them from the session to compute? remember that if you want to use javascript to calculate the totals, you'll need to render the other value(s) on the page (you could use a hidden input so it doesn't show up).

Categories

Resources