Results 1 to 4 of 4
- 03-08-2011, 05:53 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 10
- Rep Power
- 0
how to retrieve data when i select the input from the form
hi all
i have a leave report in which i have to see the report based on year and month,quarter like that.
now i have stucked actually am not getting how to retrieve
i can select the fields which i want to display but what will be the where condition
here is my code
this is the form and when i click on submit i have to retrieve the data
<HTML>
<HEAD>
<SCRIPT TYPE="TEXT/JAVASCRIPT">
function setup(ans) {
lit = ''
if (ans == 'Monthly') {
lit = lit + '<SELECT NAME="q2" >'
lit = lit + '<OPTION VALUE="">select</OPTION>'
lit = lit + '<OPTION >Jan</OPTION>'
lit = lit + '<OPTION >Feb</OPTION>'
lit = lit + '<OPTION >Mar</OPTION>'
lit = lit + '<OPTION >Apr</OPTION>'
lit = lit + '<OPTION >May</OPTION>'
lit = lit + '<OPTION >Jun</OPTION>'
lit = lit + '<OPTION >Jul</OPTION>'
lit = lit + '<OPTION >Aug</OPTION>'
lit = lit + '<OPTION >Sep</OPTION>'
lit = lit + '<OPTION >Oct</OPTION>'
lit = lit + '<OPTION >Nov</OPTION>'
lit = lit + '<OPTION >Dec</OPTION>'
lit = lit + '</SELECT>'
}
if (ans == 'Quarterly' ) {
lit = lit + '<SELECT NAME="q2" >'
lit = lit + '<OPTION VALUE="">select</OPTION>'
lit = lit + '<OPTION >01-Jan to 31-Mar</OPTION>'
lit = lit + '<OPTION >01-Apr to 30-Jun</OPTION>'
lit = lit + '<OPTION >01-Jul to 30-Sep</OPTION>'
lit = lit + '<OPTION >01-Oct to 31-Dec</OPTION>'
lit = lit + '</SELECT>'
}
if (ans == 'Half-Yearly' ) {
lit = lit + '<SELECT NAME="q2" >'
lit = lit + '<OPTION VALUE="">select</OPTION>'
lit = lit + '<OPTION >01-Jan to 30-Jun</OPTION>'
lit = lit + '<OPTION >01-July to 31-Dec</OPTION>'
lit = lit + '</SELECT>'
}
if (ans == 'Yearly' ) {
lit = lit + '<SELECT NAME="q2" >'
lit = lit + '<OPTION VALUE="">select</OPTION>'
lit = lit + '<OPTION >01-Jan to 31-Dec</OPTION>'
lit = lit + '</SELECT>'
}
document.getElementById('rep').innerHTML=lit
}
</SCRIPT>
</HEAD>
<BODY>
<FORM ACTION="#" NAME="quest">
<table align="center" name="lereport">
<tr>
<td>
<label for="yr">Select year</label>
</td>
<td>
<select >
<option value="0">Select</option>
<option value="1">2005</option>
<option value="2">2006</option>
<option value="3">2007</option>
<option value="4">2008</option>
<option value="1">2009</option>
<option value="2">2010</option>
<option value="3">2011</option>
<option value="4">2012</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="reptype">Report type</label>
</td>
<td>
<SELECT NAME="q1" ONCHANGE="setup(document.quest.q1.value)">
<option value="0">Select</option>
<option value="Monthly" >Monthly</option>
<option value="Quarterly">Quarterly</option>
<option value="Half-Yearly">Half-Yearly</option>
<option value="Yearly">Yearly</option>
</SELECT>
<SPAN ID="rep"></SPAN>
<td><input type="submit" value="submit"></td>
</table>
<table border="1" >
<tr>
<th>LeaveType</th>
<th>LeaveId</th>
<th>EName</th>
<th> EId </th>
<th>  From   </th>
<th>     To     </th>
<th>Tot leaves</th>
<th>Availed leaves</th>
<th>Bal leaves</th>
<th>Recom by</th>
<th>AppAuth</th>
<th>Status</th>
</tr>
</table>
</FORM>
</BODY>
</HTML>
- 03-08-2011, 08:31 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
What code have you tried in your servlet?
- 03-08-2011, 10:31 AM #3
Member
- Join Date
- Feb 2011
- Posts
- 10
- Rep Power
- 0
to retrieve data into a table i have used this code
<!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>display data from the table using jsp</title>
</head>
<body>
<h2 align="center">Data from the table 'leave_info' of database 'empLeave'</h2>
<%
try {
String connectionURL = "jdbc:mysql://192.168.1.15:3306/empLeave";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
Class.forName("com.mysql.jdbc.Driver").newInstance ();
connection = DriverManager.getConnection(connectionURL, "root", "notallowed");
statement = connection.createStatement();
String QueryString = "SELECT * from leave_info";
rs = statement.executeQuery(QueryString);
%>
<TABLE cellpadding="15" border="1" align="center">
<%
while (rs.next()) {
%>
<TR>
<TD><%=rs.getString(1)%></TD>
<TD><%=rs.getString(2)%></TD>
<TD><%=rs.getString(3)%></TD>
<TD><%=rs.getString(4)%></TD>
<TD><%=rs.getString(5)%></TD>
<TD><%=rs.getString(6)%></TD>
<TD><%=rs.getString(7)%></TD>
<TD><%=rs.getString(8)%></TD>
<TD><%=rs.getString(9)%></TD>
<TD><%=rs.getString(10)%></TD>
<TD><%=rs.getString(11)%></TD>
<TD><%=rs.getString(12)%></TD>
<TD><%=rs.getString(13)%></TD>
<TD><%=rs.getString(14)%></TD>
<TD><%=rs.getString(15)%></TD>
<TD><%=rs.getString(16)%></TD>
</TR>
<% } %>
<%
rs.close();
statement.close();
connection.close();
} catch (Exception ex) {
%>
</font>
<font size="+3" color="red"></b>
<%
out.println("Unable to connect to database.");
}
%>
</TABLE><TABLE align="center">
<TR>
<TD><FORM ACTION="retrieve.jsp" method="get" >
<button type="submit">Back</button></TD>
</TR>
</TABLE>
</font>
</body>
</html>
i want apply the same logic
but now my problem is i have to retrieve data when the user selects the year and the type .
so what i have to give in where condition y bcoz the user is selecting it from the browser.
- 03-08-2011, 10:39 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Why do people learn this stuff via JSPs?
It's sooo wrong.
All that db code should be in a servlet.
I realise this is probably how you're being taught, but it really is the wrong way round.
Anyway do you know SQL?
Do you know how to get parameters from a request?
If not then you need to learn about both of those things, and probably not while writing a JSP page.
Similar Threads
-
Youtube API - retrieve video on user input
By Jman85 in forum New To JavaReplies: 4Last Post: 11-11-2010, 06:15 AM -
Create a form, input some data and save to file
By cselic in forum AWT / SwingReplies: 5Last Post: 05-07-2010, 12:28 PM -
How do I retrieve a input to another page?
By syferite in forum AWT / SwingReplies: 2Last Post: 02-05-2010, 01:30 AM -
[SELENIUM] Retrieve the value of a hidden input type
By gecko753 in forum Web FrameworksReplies: 1Last Post: 11-04-2009, 03:32 PM -
enctype=multipart/form-data with form data in struts
By vk_satheesh in forum New To JavaReplies: 0Last Post: 09-19-2008, 12:48 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks