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).
Related
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...:)
I want to insert user related information into table(users),When i am creating the form i have used drop-down list.There are two tables(users and department) in my database.I want to show the name of all the departments of table department in the drop down list(so that the user selects that department name) and insert into table users. How should i do this?
file name-c_user.jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>create</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h1>Create User</h1>
<br>
<h2><a href='logout.jsp'>Log out</a></h2>
<br>
<h3><a href='success.jsp'>Go Back</a></h3>
<form method="post" action="registration.jsp">
<center>
<table border="1" width="30%" cellpadding="3">
<thead>
<tr>
<th colspan="2">Login Here</th>
</tr>
</thead>
<tbody>
<tr>
<td>User Name :</td>
<td><input type="text" name="uname" value="" /></td>
</tr>
<tr>
<td>User Id :</td>
<td><input type="text" name="uid" value="" /></td>
</tr>
<tr>
<td>Department :</td>
<td><select name="departments">
<option></option>
<option></option>
</select></td>
</tr>
<tr>
<td>Email Id :</td>
<td><input type="text" name="email" value="" /></td>
</tr>
<tr>
<td>Mobile No. :</td>
<td><input type="text" name="mobile" value="" /></td>
</tr>
<tr>
<td>Password :</td>
<td><input type="password" name="pass" value="" /></td>
</tr>
<tr>
<td><input type="submit" value="Login" /></td>
<td><input type="reset" value="Reset" /></td>
</tr>
</tbody>
</table>
</center>
</form>
</body>
</html>
file name-registration.jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%# page import ="java.sql.*" %>
<%
String user = request.getParameter("uname");
String id = request.getParameter("uid");
String email = request.getParameter("email");
String mobile = request.getParameter("mobile");
String pwd = request.getParameter("pass");
String department="";
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/login",
"root", "root");
Statement st = con.createStatement();
//ResultSet rs;
int i = st.executeUpdate("insert into users(uname, id, department, email, mobile, pass) values ('" + user + "','" + id + "','" + department + "','" + email + "','" + mobile + "','" + pwd + "')");
if (i > 0) {
//session.setAttribute("userid", user);
response.sendRedirect("welcome.jsp");
// out.print("Registration Successfull!"+"<a href='index.jsp'>Go to Login</a>");
} else {
response.sendRedirect("c_user.jsp");
}
%>
</body>
</html>
<select>
<%
ResultSet rs1=state.executeQuery(" select department from your table");
while(rs.next()){
%>
<option value="<%rs.getString(1)"%>><%rs.getString(1)"%></option>
<%}%>
</select>
try this code
First of all change column department to departmentid in users table and make foreign key in users table and use department table as a reference table
then after
just do this code on your page c_user.jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>create</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h1>Create User</h1>
<br>
<h2><a href='logout.jsp'>Log out</a></h2>
<br>
<h3><a href='success.jsp'>Go Back</a></h3>
<form method="post" action="registration.jsp">
<center>
<table border="1" width="30%" cellpadding="3">
<thead>
<tr>
<th colspan="2">Login Here</th>
</tr>
</thead>
<tbody>
<tr>
<td>User Name :</td>
<td><input type="text" name="uname" value="" /></td>
</tr>
<tr>
<td>User Id :</td>
<td><input type="text" name="uid" value="" /></td>
</tr>
<tr>
<td>Department :</td>
<td><select name="departments">
<%try{
String sql="select * from department";
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/login",
"root", "root");
Statement st = con.createStatement();
ResultSet rs=st.executeQuery(sql);
while(rs.next()){
%>
<option value="<%=rs.getInt("departmentid")%>"><%=rs.getString("departmentname")%></option>
<%}
rs.close();
st.close();
con.close();
}catch(Exception e){
e.printStackTrace();
}%>
</select></td>
</tr>
<tr>
<td>Email Id :</td>
<td><input type="text" name="email" value="" /></td>
</tr>
<tr>
<td>Mobile No. :</td>
<td><input type="text" name="mobile" value="" /></td>
</tr>
<tr>
<td>Password :</td>
<td><input type="password" name="pass" value="" /></td>
</tr>
<tr>
<td><input type="submit" value="Login" /></td>
<td><input type="reset" value="Reset" /></td>
</tr>
</tbody>
</table>
</center>
</form>
</body>
</html>
then after submit this departmentid will be stored in users table and don't miss to change query of insert like this
change insert query in registration.jsp page
insert into users(uname, id, departmentid, email, mobile, pass) values ('" + user + "','" + id + "','" + departmentid + "','" + email + "','" + mobile + "','" + pwd + "')
Use the ajax call to display the department name in ui and insert suitable it into your users table
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.
I have my Struts2 Action class as below and I am expecting the actionerror message should be displayed in my JSP page using the tag: <s:actionerror />
However the message did not show up, and I've found that if I change in the getModel() method return form; to return null;, the error message could be displayed again! How can I show the error message at the same time returning the form object in getModel() method?
public class StartSearchApplicationAction
extends ActionSupport
implements ModelDriven, SessionAware {
protected Map<String, Object> session;
private Formbean form;
public String execute() {
addActionError("Testing Error Message");
session.put("form", form);
return "success";
}
public Formbean getModel() {
form = (Formbean) session.get("form");
if (form == null) {
form = new Formbean();
}
return form;
}
public void setSession(Map<String, Object> session){
this.session = session;
}
}
Updated on 20-Oct-2015 - My JSP (it is the tiles template page)
Note that even I change the statement <s:if test='%{#session.hasError == "Y"}'> to <s:if test="hasActionErrors()">, the result is the same
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%# page language="java" %>
<%# page contentType="text/html; charset=UTF-8" %>
<%# page errorPage="/jsp/error.jsp" %>
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<html>
<head>
<title><s:text name="global.heading.title"/></title>
</head>
<body>
<table class="main" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="860" valign="top" bgcolor="#FFFFFF">
<table border="0" valign="top" align="left">
<s:if test='%{#session.hasError == "Y"}'>
<tr>
<table width="500" border="0" cellspacing="0" cellpadding="2" align="center" bgcolor="#006600">
<tr>
<td width="16" class="ErrorMessageBoxTitle"><img src="/<s:text name="global.system.root"/>/images/smessage.gif" width="16" height="14" align="absmiddle" alt="System Errors"></td>
</tr>
<tr>
<td colspan="2" class="FixTdSize">
<table width="496" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF">
<tr>
<td align="center" class="FixTdSize">
<table border="0" cellspacing="12" cellpadding="0" width="480">
<tr>
<td width="35" class="ErrorMessageTitle"><img src="/<s:text name="global.system.root"/>/images/messager.gif" width="31" height="31" alt="System Errors"></td>
<td class="ErrorMessageTitle" width="409"> </td>
</tr>
<tr>
<td width="35" class="ErrorMessageBody"> </td>
<td class="label" width="409"><font color=red><s:actionerror/></font></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</tr>
<tr><td> </td></tr>
</s:if>
<tr>
<td height="30"><tiles:insertAttribute name="searchpanel"/></td>
</tr>
<tr>
<td><img src="/<s:text name="global.system.root"/>/images/line.gif" width="100%" height="2"></td>
</tr>
<tr>
<td><tiles:insertAttribute name="message"/></td>
</tr>
<tr>
<td><tiles:insertAttribute name="body"/></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</table>
<tiles:insertAttribute name="menu"/>
</body>
</html>
after investigation I finally did it with referencing to this question:
Passing parameters to action through ModelDriven in Struts 2
I think the reason is Modeldriven interceptor pushes the model on top of the value stack (i.e. 0-index) and thus the jsp could not access the actionError (the original 0-index was the action class).
Instead of using <s:actionerror/>, the page could able to display the actionError using <s:property value="[1].actionErrors[0]"/>, I am not sure whether this is a good approach but it serve the purpose.
Hi I'm trying to make a "Clear Cart" button in my java code but i'm having difficulty.
I've been trying for a couple of hours but i can't get it to work
I think it has something to do mostly with the first part that has all the strings and variables.
Here's the code:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%# page errorPage="errorpage.jsp" %>
<jsp:useBean id="cart" scope="session" class="beans.ShoppingCart" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>the Game Store</title>
</head>
<body>
<%
String id = request.getParameter("id");
if ( id != null ) {
String desc = request.getParameter("desc");
Float price = new Float(request.getParameter("price"));
cart.addItem(id, desc, price.floatValue(), 1);
}
%>
Shopping Cart Quantity:
<%=cart.getNumOfItems() %>
<hr>
<center><h3>Games</h3></center>
<table border="1" width="300" cellspacing="0"
cellpadding="2" align="center">
<tr><th>Description</th><th>Price</th></tr>
<tr>
<form action="AddToShoppingCart.jsp" method="post">
<td>Goat Simulator</td>
<td>$11.95</td>
<td><input type="submit" name="Submit" value="Add"></td>
<input type="hidden" name="id" value="1">
<input type="hidden" name="desc" value="Goat Simulator">
<input type="hidden" name="price" value="11.95">
</form>
</tr>
<tr>
<form action="AddToShoppingCart.jsp" method="post">
<td>Metal Gear Solid V</td>
<td>$59.99</td>
<td><input type="submit" name="Submit" value="Add"></td>
<input type="hidden" name="id" value="2">
<input type="hidden" name="desc" value="Metal Gear Solid V">
<input type="hidden" name="price" value="59.99">
</form>
</tr>
<tr>
<form action="AddToShoppingCart.jsp" method="post">
<input type ="submit" name="empty" id="empty-button" value="Empty Cart"/>
</form>
Clear
</tr>
</table>
</body>
</html>
Here's the second page for the entire page
<%# page errorPage="errorpage.jsp" %>
<%# page import="java.util.*" %>
<jsp:useBean id="cart" scope="session" class="beans.ShoppingCart" />
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Shopping Cart Contents</title>
</head>
<body>
<center>
<table width="300" border="1" cellspacing="0"
cellpadding="2" border="0">
<caption><b>Shopping Cart Contents</b></caption>
<tr>
<th>Description</th>
<th>Price</th>
<th>Quantity</th>
</tr>
<%
Enumeration e = cart.getEnumeration();
String[] tmpItem;
// Iterate over the cart
while (e.hasMoreElements()) {
tmpItem = (String[])e.nextElement();
%>
<tr>
<td><%=tmpItem[1] %></td>
<td align="center">$<%=tmpItem[2] %></td>
<td align="center"><%=tmpItem[3] %></td>
</tr>
<%
}
%>
</table>
</center>
Back to Catalog
</body>
</html>