vinu pillai

Greenhorn
+ Follow
since Oct 05, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by vinu pillai

hi,
Thanks for the suggestion buddy...
Cookies will work but there are several disadvantages behind using cookies as they expire without informing the user or client...and what if the client disables cookies through his browser...what i wanted to know that HttpSession is working very fine but there is some prob..so if apart from u if anyone know plz suggest a way...i am giving away the code too...
HERE IS THE CODE:-
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class TestServlet extends HttpServlet {
static String URLRedirect = "http://localhost:8080/redirectPage.htm";
static String BadRedirect = "http://localhost:8080/TestServlet.htm";
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Connection connection = null;
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String dsn = "jdbc dbc:test";
String uname = "scott";
String pword = "tiger";
String user_id = request.getParameter("userid");
String pass_word = request.getParameter("password");
//String dbquery = "select * from adminpanel where USERID ='" +user_id+ "'and PASSWORD ='" +pass_word+"'";
String dbquery = "select * from adminpanel where USERID = ? and PASSWORD = ?";
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>This is a Login Page</title></head>");
out.println("<body>");
try {
Class.forName(driver);
connection = DriverManager.getConnection(dsn, uname, pword);
PreparedStatement preparedStatement = connection.prepareStatement(dbquery);
preparedStatement.setString(1,user_id);
preparedStatement.setString(2,pass_word);
ResultSet resultset = preparedStatement.executeQuery();
if(resultset.next()==true) {
HttpSession session = request.getSession(true);
session.putValue(user_id, pass_word);
String getvalue = (String)session.getValue(pass_word);
if(getvalue.equals(pass_word)) {
trueredirectPage(request, response);
System.out.println("U are being redirected to " +URLRedirect);
System.out.println("The value of ur session is " +getvalue);
}
}
else {
System.out.println("Wrong Validity...Redirecting to .."+BadRedirect);
badredirectPage(request, response);
System.out.println("INVALID USERNAME AND PASSWORD");
}
preparedStatement.close();
connection.close();
}catch(Exception exception) {
System.out.println("The Error is " +exception.toString());
}

out.println("</body>");
out.println("</html>");
}
private void trueredirectPage(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
response.sendRedirect(URLRedirect);
}
private void badredirectPage(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
response.sendRedirect(URLRedirect);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
In this code the problem is that when I try to access directly the page which i am redirecting..(i.e String BadRedirect)..it's not redirecting the page which i wanted...(i.e String URLRedirect)..plz help..to overcome the problem..
Thanks
vinu

Originally posted by Syam Veerakumar:
U have to set cookies in the client machine for doing that I guess if i am wrong pls correct me.


16 years ago
Thanks for the solution man..
but what if i am making a project on mail by using HttpSession
and want to maintain session till he has logged in...and when he log out or closes the browser then he has to log in by entering password in the field...
thanks
Vinu

Originally posted by Andre Moo:
Incase you were wondering, the session is maintained for you by the container across pages - you don't need to worry about any of that!


16 years ago
How can i maintain a session through out the five different pages with the same session id given to the user..??
[This message has been edited by vinu pillai (edited October 15, 2001).]
16 years ago
thanks buddy,
I will deploy it soon...
bye...
Thanks again

Originally posted by Toyin Sogeke:
Hello Sir,
Create javabean as follows:
// Assign page name, very important
package example.test;
public class LoginCheck {
private String userName = "";
private String passWord = "";
// Default constructor is required.
public LoginCheck() { }
// JavaBean needs setter and getter methods
public void setUserName(String user) {
this.userName = user;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
// You can define a method here with
// your database connection details.
public boolean authenticate(String user) {
return (this.username.equalsIgnoreCase(this.userName));
}
}
You can use a JavaBean as follows in a JSP:
<jsp:useBean id="loginBean"<br /> scope="page"<br /> class="example.test.LoginCheck">
<jsp:setProperty name="loginBean" property="*"/>
</jsp:useBean>
<%<br /> // You can call and use a JavaBean as follows:<br /> boolean isLoggedIn = loginBean.authenticate("RanchHand");<br /> %>
Hope this helps.
Cheers


Thanks buddy...

Originally posted by vivek makode:
take the result set data in an integer array and not a single number.
u have taken int num.
take int num[];


hi all,
How to make a bean for connecting to Database through JSP..???
I have no idea what bean are....i hard code the jdbc syntaxes in the scriptlet tag itself...but some say that making a connection bean is proper way to show the database results...
i don't know how to create bean ...can help me out to find the best tutorial links to JavaBeans..

Thanks..
VINU
How can i find a missing number stored in database say an oracle database...Like for e.g there are 1 - 10 numbers in database...and the numbers 5 and 7 are missing in...so..! i want to print these two missing numbers in front end ....The code which i coded is ..
import java.sql.*;
class testNum {
public static void main(String args[]) throws Exception {
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc dbc:Category_Trans";
String username = "vinu";
String password = "vinu";
Connection connection = null;
ResultSet rset = null;
int num = 0;
int i;
Class.forName(driver);
connection = DriverManager.getConnection(url, username, password);
Statement statement = connection.createStatement();
rset = statement.executeQuery("select * from number_test");
if(rset != null) {
while(rset.next()) {
num = rset.getInt(1);
//System.out.println(num);
}
}
for(i=1;i<=num;i++) {
System.out.println(i);
/*if(i!=num)
System.out.println("1.." +num);
else
System.out.println("2.." +i);*/
}
System.out.println();
}
}
but it's not printing what i wanted..
plz if there is any solution then help me out...

thanks
Vinu