Results 1 to 8 of 8
- 08-25-2010, 05:56 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 11
- Rep Power
- 0
finding details in database using JSP and forwards user to a HTML page
The following HTML displays a form prompting the user to enter a username and a password. On clicking on the Login button, Logon.jsp is called.
I need to write the code for Logon.jsp, which reads in the user’s name and password and checks if this is contained in a database table called registrations.
If a match is found the user is allowed access to an HTML page called MyHomePage.html, if a match is not found a page stating access denied is displayed.
:)
<html>
<body>
<br>
<p><center>Please enter your username and password</center></p>
<br>
<form action = "http://localhost:8080/examples/Logon.jsp"
method = "get">
<center> username <input type ="text" name = "username"></center><br>
<center> password <input type ="password" name = "password"> </center><br>
<center><input type ="submit" name = "submit" value = " Login"> </center>
</form>
</body>
</html>
- 08-25-2010, 07:07 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,380
- Blog Entries
- 7
- Rep Power
- 17
A JSP should deal with the presentation of an html page; not with a database layer. It should be left to an ordinary Java class (a bean mayhap?) A Servlet should be ignorant of all that stuff as well. Just create a simple class that checks the user's credentials and returns true or false. If true a session can be created and passed to the JSP, otherwise no session is created. The JSP couldn't and shouldn't care less but base its decision what to display on the presence (or absence) of a session object. Never put any database code in a JSP; it doesn't belong there.
kind regards,
Jos
- 08-27-2010, 03:41 AM #3
Member
- Join Date
- Jun 2010
- Posts
- 5
- Rep Power
- 0
let me give u a kind of psuedocode
there are so many ways to perform the task,since you have a html login page wat u do is to create a servlet that u will forward the request to the required page
the servlet ensures that the request parameters are not null or empty strings
then get a connection to the database and perform some queries like
select name from table where password is password .
if{ resultset.next is true and resultset.name is equal to name then do
create a Property object p and do p.setProperty("name""value of name")
get sessionobject and pass p to it as an attribute and get a requestdispatcher object of the logon page and forward it with request and response objects.to the logonpage.jsp}
else get a requestdispatcher and foward back to the login page.html
in the jsp logon.jsp use ${p.name} to get the value of the session atribute name
just follow the above steps and code well you will get it is simple!:)
- 08-27-2010, 08:42 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
If you're going to give advice at least make sure it's good advice. The check for authentication of a user is a single bit of SQL, which either returns a result or not. There is no need to check the contents of the result.
Your method above is bizarre...at least the usual mistake makes some degree of sense (select password from users where name = name, then check the password in Java), but selecting based on the password?
However, both methods are wrong. You select based on both name and password.
- 08-27-2010, 01:05 PM #5
Member
- Join Date
- Mar 2010
- Posts
- 9
- Rep Power
- 0
dynamic query in jsp
hi
we are developing page that contain checkbox and textbox which are dynamically generated.when we click on check box textbox will be enable.we enter value in textbox.now we want to insert that values in database on click event of button. rest of values should not enter in database, but we are not manupulate dynamic button and check box.
Source Code:
<%@page session="false" %>
<%@page import="java.util.*"%>
<%@page import="java.sql.*"%>
<html>
<head> </head>
<body>
<%
Statement st=null;
Connection con=null;
ResultSet rs=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("Jdbc:Odbc:unisoft ");
st = con.createStatement();
rs = st.executeQuery("SELECT * from course");
%>
<form name="form" method="post" action="">
<table border="1" align="center" width=650 height=0 cellpadding=8>
<tr>
<td colspan=3> <font size=4> Fees Structure <hr> </font> </td>
</tr>
<tr>
<td width=92> Course Name </td>
<td width="7"> : </td>
<td width="200"> <select name="course">
<option value="abc">ABC</option>
<% while(rs.next())
{
%>
<option value="<%= rs.getString(1)%>"> <%= rs.getString(2) %></option>
<% } %>
</select> </td>
<%
}
finally
{
if(st!=null) st.close();
//if(rs!=null) rs.close();
if(con!=null) con.close();
}
%>
</tr>
</table>
<table border="1" align="center" width=650 height=0 cellpadding=8>
<tr>
<td width=92> Course Name </td>
<td width="7"> : </td>
<td width="200"> <select name="course">
<option value="Day"> Day </option>
</select>
<td> </td>
</tr>
<tr align="center">
<td> <input type="button" name="next" value="Next" style="width:100"> </td>
<td> <input type="button" name="next" value="Reset" style="width:100"> </td>
<td> <input type="button" name="next" value="Cancel" style="width:100"> </td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>
help us to solve that problem.
thanks
megha
- 08-27-2010, 01:28 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Are you sandra in disguise, or are you hijacking someone elses thread?
- 08-28-2010, 03:43 AM #7
Member
- Join Date
- Jun 2010
- Posts
- 5
- Rep Power
- 0
@Tolls
thank you for the constructive criticism, am actually a newbea in programing but i just wanted to help since no body wanted to reply the post.i just have a little idea of SQL,but am sure wat i posted will work but is a little bit of a long process
thanks toll becpouse i also length some sql from you today like
select * from table where values name,password
- 08-31-2010, 09:47 AM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Ah, but people did reply to the post. This stuff should not be done in a JSP, and many of us will not provide help if people persist in going down this route.
But yes, your way will work, but it will take more processing (the db is far faster at doing this than Java would be), and is not entirely logical.
Similar Threads
-
Login page which connects to database that verifies user
By Neutrino in forum JDBCReplies: 1Last Post: 03-15-2010, 01:39 AM -
what is and how works the first ?, example.com/details?page=4
By lse123 in forum JavaServer Pages (JSP) and JSTLReplies: 4Last Post: 10-29-2009, 02:18 PM -
terminating the page if user sits idle.
By shivakumari in forum Java ServletReplies: 9Last Post: 04-11-2009, 07:46 AM -
load graphics in html page using jsp and database
By charu in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 03-04-2009, 07:12 PM -
HTML page
By bbq in forum New To JavaReplies: 1Last Post: 07-05-2007, 03:46 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks