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
Related
i have two jsp file index.jsp and login.jsp and profile.jsp.
here index.jsp has two text field name and password.
When I give right name and password login shows successful and go to success.jsp but when i give wrong password or name i want that an error message will show in same index page that is "invalid name or pass". my code is not working login.jsp is used for username and password authentication..please help me to solve this .
I have searched about RequestDispatcher but it is used in servlet class.but i want to do it in my jsp file.my code
index.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 Example</title>
</head>
<body>
<form method="post" action="login.jsp">
<center>
<table border="1" width="30%" cellpadding="3">
<thead>
<tr>
<th colspan="2" align ="left">Login Here</th><h5><%=request.getAttribute("errorMessage") %></h5>
</tr>
</thead>
<tbody>
<tr>
<td>User Name</td>
<td><input type="text" name="uname" 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>
<tr>
<td colspan="2">Yet Not Registered!! Register Here</td>
</tr>
</tbody>
</table>
</center>
</form>
</body>
login.jsp
<%# page import ="java.sql.*" %>
<%
String userid = request.getParameter("uname");
String pwd = request.getParameter("pass");
Class.forName("org.postgresql.Driver");
Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/test", "postgres", "root");
Statement st = con.createStatement();
ResultSet rs;
rs = st.executeQuery("select * from member where uname='" + userid + "' and pass='" + pwd + "'");
if (rs.next()) {
session.setAttribute("userid", userid);
//out.println("welcome " + userid);
//out.println("<a href='logout.jsp'>Log out</a>");
response.sendRedirect("success.jsp");
} else {
//out.println("Invalid password <a href='index.jsp'>try again</a>");
request.setAttribute("errorMessage", "Invalid user or password");
response.sendRedirect("index.jsp");
}
%>
In your else statement, don't use response.sendRedirect() because all the saved attributes will be lost as it's a new request, use requestDispatcher.forward() instead:
req.setAttribute("errorMessage", "Invalid user or password");
req.getRequestDispatcher("/index.jsp").forward(req, res);
The answer is in your code itself. For success you have used session.setAttribute so its working, and for login failed" you have used request.setAttribute that's why its not working. Go for session rather than request or user requestDispatcher to forward your request. And You have mansion that you used RequestDispatcher but its not working, it will not work unless you write complete statement like calling forward method of requestDispatcher.
you can do in index page in form
<div style="color:red">${errorMessage}</div>
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>
I was working with spring and read about the use of commandName in view(jsp). I have a little trouble working with it can anyone help me how to effectively use it?
i get this error when i use in my jsp page.
SEVERE: Servlet.service() for servlet [dispatcher] in context with path
[/hibernateAnnotaionWithSpring] threw exception [An exception occurred processing JSP
page /WEB-INF/jsp/userForm.jsp at line 17
14: <table>
15: <tr>
16: <td>User Name :</td>
17: <td><form:input path="name" /></td>
18: </tr>
19: <tr>
20: <td>Password :</td>
Stacktrace:] with root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for
bean name 'user' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
my code is as follows:-
when i click on submit button it should take me to userForm page
<form action="login.htm">
<table class="hundredPercent headerBackground" cellspacing="0">
<tr>
<td class="textLabel sevenPer">
Email
</td>
<td class="textField sevenPer">
<input type="text" value="" name="username">
</td>
<td class="textLabel sevenPer">
Password
</td>
<td class="textField sevenPer">
<input type="password" value="" name="password">
</td>
<td class="textField">
<input type="submit" value="Enter" name="submit" class="buttonSubmit">
</td>
<td>
</td>
<td class="textLabel">
<a href="list.htm" >Register</a>
</td>
</tr>
</table>
</form>
my controller class
#RequestMapping("/login.htm")
public String login(HttpServletRequest request,
HttpServletResponse response,ModelMap model) throws Exception {
String userName= request.getParameter("username");
String password= request.getParameter("password");
System.out.println("name===="+userName);
return "userForm";
}
finally my resultant jsp page
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Registration Page</title>
</head>
<body>
<form:form action="add.htm" commandName="user" method="POST">
<table>
<tr>
<td>User Name :</td>
<td><form:input path="name" /></td>
</tr>
<tr>
<td>Password :</td>
<td><form:password path="password" /></td>
</tr>
<tr>
<td>Gender :</td>
<td><form:radiobutton path="gender" value="M" label="M" />
<form:radiobutton
path="gender" value="F" label="F" /></td>
</tr>
<tr>
<td>Country :</td>
<td><form:select path="country">
<form:option value="0" label="Select" />
<form:option value="India" label="India" />
<form:option value="USA" label="USA" />
<form:option value="UK" label="UK" />
</form:select></td>
</tr>
<tr>
<td>About you :</td>
<td><form:textarea path="aboutYou" /></td>
</tr>
<tr>
<td>Community :</td>
<td><form:checkbox path="community" value="Spring"
label="Spring" /> <form:checkbox path="community"
value="Hibernate"
label="Hibernate" /> <form:checkbox path="community"
value="Struts"
label="Struts" /></td>
</tr>
<tr>
<td></td>
<td><form:checkbox path="mailingList"
label="Would you like to join our mailinglist?" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Register"></td>
</tr>
</table>
</form:form>
</body>
</html>
Can anyone please help on this?
Thanks in advance
You need to add an empty user to the model.
#RequestMapping("/login.htm")
public String login(HttpServletRequest request,
HttpServletResponse response, ModelMap model) throws Exception {
String userName= request.getParameter("username");
String password= request.getParameter("password");
System.out.println("name===="+userName);
model.addAttribute("user", new User(...)):
return "userForm";
}
in addition you have to write:
<form:form action="add.htm" modelAttribute="user" method="POST">
(modelAttribute instead of commandName)
Anyway your controller is a bit uncommon. Try This:
#RequestMapping(value="/login.htm" method = RequestMethod.GET)
public String loginForm(ModelMap model) throws Exception {
model.addAttribute("user", new User("", "")):
return "userForm";
}
#RequestMapping(value="/login.htm" method = RequestMethod.POST)
public String login(User user) throws Exception {
String userName= user.getUsername();
String password= user.getPassword();
...
}
/** The command class */
public class User{
private String username;
private String password:
Getter and Setter
}
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).
How can I access the values in the textBox to pass it into a SQL database. What will be the text-box's unique name in each row?
The code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%# page import="java.sql.*" %>
<%# page import="java.io.*" %>
<html>
<head><title>orderSample</title>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
$(document).ready(function() {
$('.add').click(function() {
$(this).closest('tr').find('.quantity').attr('disabled', !this.checked);
});
});
</script>
</head>
<body bgcolor="white">
<form method=post name=orderForm>
<h1>Data from the table 'item details' of database 'caffe' in sql </h1>
<%
System.out.println("adadadasasasasasasasasas");
int i = 0;
%>
<TABLE cellpadding="15" border="1" style="background-color: #ffffcc;">
<TR>
<TD>ORDER ID</TD>
<TD>ORDER PRICE</TD>
<TD>Quantity</TD>
<TD>Add Item</TD>
</TR>
<%do{
System.out.println("I am in Ob");
%>
<TR>
<TD>asdadsas</TD>
<TD>asdasdasd</TD>
<td><input type="checkbox" class="add" /></td>
<td><input type="text" class="quantity" /></td>
<!-- <td><INPUT TYPE="TEXT" NAME="NAME_TEXT<%=i%>" VALUE="" IsEnabled="{Binding ElementName=checkBox1, Path=IsChecked}"/></td>
<td><INPUT TYPE="TEXT" NAME="NAME_TEXT<%=i%>" VALUE="" /></td>
<td><input type="checkbox" name="others<%=i%>" onclick="enable_text(this.checked,<%=i%>)" ></td>-->
</TR>
<%i++; }while(i<2); %>
</TABLE>
</form>
</body>
</html>
Either give them all the same name
<td><input type="text" name="name" /></td>
so that you can use
String[] values = request.getParameterValues("name");
Or give them all the same prefix
<td><input type="text" name="name${someDynamicValue}" /></td>
so that you can use
for (Entry<String, String[]> entry : request.getParameterMap().entrySet()) {
if (entry.getKey().startsWith("name")) {
String value = entry.getValue()[0];
// Add to list?
}
}
Or when it is an incremental suffix
<td><input type="text" name="name${index}" /></td>
then use
for (int i = 0; i < Integer.MAX_VALUE; i++) {
String value = request.getParameter("name" + i);
if (value == null) {
break;
}
// Add to list?
}