I am a newbie trying to create a simple web application using JSP and Mysql.
I am using following thing:
Eclipse EE IDE
Tomcat 7.0
Dtabase: MySQL
MySQL Connector
In my page I have row user add row dynamically that s work fine. I want my values should get stored in database after submit.I have searched lot on net but not find anything which can solve problem.I am giving code of current page.I know have to do connection also however I tried but not succeeded.
Thanks in advance.
JSP & Javascript:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#add").click(function() {
$('#mytable tbody>tr:last').clone(true).insertAfter('#mytable tbody>tr:last');
$('#mytable tbody>tr:last #name').val('');
$("#mytable tbody>tr:last").each(function() {this.reset();});
return false;
});
});
</script>
</head>
<body>
<form>
<a id="add" href="javascript:void(0)">Add another Credit card</a>
<table id="mytable" width="300" border="1" cellspacing="0" cellpadding="2">
<tbody>
<tr class="person">
<td><input type="text" name="name" id="name" /></td>
<td><input type="button" value="name" /></td>
<td><select>
<option>value1</option>
<option>value2</option></select>
<td><input type="text" name="name" id="name" /></td>
</tr>
</tbody>
</table>
<input type="submit" value="submit">
</form>
Logout
</body>
</html>
Related
I want to get table data from table to new database through jsp servlet this is my sample code in jsp this table contains database elements
I struggled for a week. Please help me.
I want to get table data from table to new database through jsp servlet this is my sample code in jsp this table contains database elements
<%#page import="java.sql.Connection"%>
<%#page import="java.sql.PreparedStatement"%>
<%#page import="Servlets.Db"%>
<%#page import="java.sql.ResultSet"%>
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<h1>Place your Order</h1>
<div class="jumbotron">
<form action="order" method="post">
<!--
<label>name</label>
<input class="form-control" name="name" type="text" >
<label>Member Id</label>
<input class="form-control" name="memberid" type="text" >
<label>Orders</label>
<div class="container">
<div class="row">
<div class="jumbotron">
-->
<table class="table">
<tr>
<th>id</th>
<th>name</th>
<th>quantity</th>
</tr>
<%
Connection con=Db.getCon();
String sql="SELECT * FROM drugs";
PreparedStatement ps=con.prepareStatement(sql);
ResultSet rs=ps.executeQuery();
while(rs.next()) {
%>
<tr>
<td><input type="text" name="id" value="<%=rs.getInt("id") %>"></td>
<td><input type="text" name="name" value="<%=rs.getString("name") %>"></td>
<td><input type="text" name="quntity"></td>
</tr>
<%
}
%>
</table>
<input type="submit" value="submit order">
</form>
</div>
</div>
<div class="row">
<%# include file="WEB-INF/Footer.jsp" %>
</div>
</div>
</body>
</html>
The work you done is get data from database and show data in jsp,if you want to put data into database,you should change sql to "add" and jsp to "input".
I am having task that i have to move the selected row to top in table and when i refresh the page i want to restore the previous changes.
I completed the moveRow logic.
But i am not getting how to restore the row data, please assist me for this.
Below is my code
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script language="JavaScript">
var whichrow = false;
var TableLocation;
function thisrow(x)
{
TableLocation = x.sectionRowIndex;
}
function MoveUp()
{
var tablebody = document.getElementById('table1');
if(TableLocation > 0)
{
tablebody.moveRow(TableLocation, 1);
}
}
</script>
</head>
<body>
<form>
<table id="table1" name="table1" border="1">
<tr>
<th>Name</th>
<th>Address</th>
<th>Select</th>
</tr>
<tr id="tr3" onclick="thisrow(this)">
<td><input type="text" name="name"></td>
<td><input type="text" name="address"></td>
<td><input type="checkbox" name="checkbox1"></td>
</tr>
<tr id="tr4" onclick="thisrow(this)">
<td><input type="text" name="name"></td>
<td><input type="text" name="address"></td>
<td><input type="checkbox" name="checkbox1"></td>
</tr >
<tr id="tr5" onclick="thisrow(this)">
<td><input type="text" name="name"></td>
<td><input type="text" name="address"></td>
<td ><input type="checkbox" name="checkbox1"></td>
</tr>
</table>
<input type="button" value="move row up" onClick="MoveUp();">
</form>
</body>
</html>
Thanx in advance...
looking forword for your reply.
You need to save your changes on the server to reload your page (you don't need to save on database, you can store it in the session and use use on the next page rendering). Then you can use your javascript to move up/down your rows.
I suggest you to put data-attributes in your html tags to order it in javascript or order on the server before rendering.
I'm starting to study struts and I have a problem using resource properties file
some text on page is displayed as this:
???login.message???
???login.username???
???login.password???
but some other messages are correctly taken from properties file. I think that the propertis file is correctly configured but I'm missing something to display anything correctly.
the file ApplicationResources.properties
# Resources for Login Project
# Struts Validator Error Messages
# These two resources are used by Struts HTML tag library
# to format messages. In this case we make sure that errors
# are red so that they can be noticed.
errors.header=<font color="red">*
errors.footer=</font>
#errors associated with the Login page
error.username.required=username required.
error.password.required=password required
error.login.invalid=The system could not verify your username or password. Is your CAPS LOCK on? Please try again.
#login page text
login.title=this is a title
login.message=please log in
login.username=username:
login.password=password:
login.button.signon=Log In
#loggedin page text
loggedin.title=Login Project
loggedin.msg=Benvenuto, {0}. You are now logged in.
"error.login.invalid" is correctly displayed and "error.username.required" too
the login label not
this is my jsp page
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%# taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%# taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<html:html locale="true"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<fmt:bundle basename="ApplicationResources"/>
<title><fmt:message key="login.title"/></title>
</head>
<body>
<html:errors property="login"/>
<html:form action="login.do" focus="userName" >
<table align="center">
<tr align="center">
<td><H1><fmt:message key="login.message"/></H1></td>
</tr>
<tr align="center">
<td>
<table align="center">
<tr>
<td align="right">
<fmt:message key="login.username"/>
</td>
<td align="left">
<html:text property="userName"
size="15"
maxlength="15" />
<html:errors property="userName" />
</td>
</tr>
<tr>
<td align="right">
<fmt:message key="login.password"/>
</td>
<td align="left">
<html:password property="password"
size="15"
maxlength="15"
redisplay="false"/>
<html:errors property="password" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<html:submit>
<fmt:message key="login.button.signon"/>
</html:submit>
</td>
</tr>
</table>
</td>
</tr>
</table>
</html:form>
</body>
</html>
Can you help me ?
tkz
Your
<fmt:message ... />
tags need to be inside an
<fmt:bundle ... >
tag. Currently you are closing your bundle tag right away
<fmt:bundle basename="ApplicationResources"/>
Instead, open it
<fmt:bundle basename="ApplicationResources">
and close it
</fmt:bundle>
when you no longer need it, possibly at the end of your JSP. Nest your
<fmt:message key="login.title"/>
tags inside it.
I'm brand new to the javascript. I'm trying to call a javaScript function from my jsp.Its not working. I was trying to debug it through bugzila. It saying "No Javascript on this page"
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4 /loose.dtd">
<html>
<script type="text/javascript" src="ajaxs.js"></script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<%
out.println("Bismillahir Rahmanir Rahim");
%>
<jsp:useBean id="numBean" class="beans.NumberBean">
<jsp:setProperty name="numBean" property="*" />
</jsp:useBean>
<form action="index.jsp" method="post">
<table>
<tr>
<td>Enter Integers:</td>
<td><input type="text" id="inputString" name="inputString"
value="<jsp:getProperty name="numBean" property="inputString" />"
/> </td>
<td>(Use semi-colon to separate number)</td>
</tr>
<tr>
<td>M - number of largest element to find.:</td>
<td>
<input type="text" id="nthHighest" name="nthHighest"
value="<jsp:getProperty name="numBean" property="nthHighest" />" />
</td>
</tr>
</table>
<input type="submit" value="Identify" onclick="ajaxFunction()" />
<div id="result"></div>
</form>
</body>
</html>
I'm trying to call "ajaxFunction()" on onclick event.
I included js file as following at the top:
<script type="text/javascript" src="ajaxs.js"></script>
can u pls help me to identify what I'm doing wrong here...
Thanks in advance
Try with including script tag with "src="ajaxs.js" (your current script that including "src="ajaxs.js") within head tag.The contents within head tag load at the loading page .
thanks....
Background: I have a Java webserver class (NanoHTTPD) which my application extends by adding sessions, page templates, authentication, and dynamic content. I wanted to make the application self contained and not rely on anything but SQLite. It is meant to run with only Java and SQLite installed.
Now for my problem. I am testing a simple index page with only Logout link. If a user goes to the index without logging in, they are HTTP redirected to the Login page. When they POST the credentials and are validated, it returns them to the index page. If you click the Logout link in Firefox, my application only receives a URI to the index('/'). Following the same process in Chrome it logs the user out as expected. I do no modify the GET URL at any point; I only run uri.equals("/logout/"). Is there any reason why Firefox would interpret this link differently?
Login HTML:
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">
<html>
<head>
<title>Login</title>
</head>
<body>
<h1>Login</h1>
<div>
<p></p>
<form method="post" action="/login/">
<table>
<tr>
<td>
<label for="username">Username</label>
<input type="text" name="username" id="username" maxlength="100" />
</td>
<td>
<label for="password">Password</label>
<input type="password" name="password" id="password" />
</td>
<td></td>
<td>
<input type="submit" value="Sign In" />
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
Index HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Index</title>
</head>
<body>
<h1>Index</h1>
Logout
</body>
</html>
The code for matching URL's is just .equals() and the only code running before this is NanoHTTPD which is located here: https://github.com/elonen/nanohttpd/blob/master/NanoHTTPD.java
One more thing, I have made a page, "test.html", to which I copied the source from above. Firefox does not handle it correctly either and stays on the page without giving a File Not Found error. Additionally, if I change the page to use "/logout1/", everything works.