The Artima Developer Community
Sponsored Link

Java Answers Forum
Servlet Query!

2 replies on 1 page. Most recent reply: Nov 3, 2005 10:53 PM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
monisha kapur

Posts: 1
Nickname: monisha
Registered: Nov, 2005

Servlet Query! Posted: Nov 3, 2005 9:38 PM
Reply to this message Reply
Advertisement
Hi..
I am new to servlets . My first program executed..
but the second one is having problem as all is going right but when i submit the uid and pwd through the html i get a blank page.it shows nothing.


Servlet Code:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;


public class login extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
String uid=req.getParameter("t1");
String pwd=req.getParameter("t2");

PrintWriter out=res.getWriter();

res.setContentType("text/html");

try
{
Class.forName("su n.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc : odbc:ms","scott","tiger");

PreparedStatement psm=con.prepareStatement("select * from reg where uid1=? and pwd=?");
psm.setString(1,uid);
psm.setString(1,pwd);
ResultSet rs=psm.executeQuery();
if(rs.next())
{
out.println("<html><head>< ;title>WELCOME</title></head>");
out.println("<body><b&g t;<i>Hello user "+uid+"</b></i>");
out.println("</body></html>");
}
els e res.sendRedirect("http://localhost:8080/login.html");
}
catch(Exception e)
{
e.printStackTrace();}
}
}

plz help me out ...
thanks .


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Servlet Query! Posted: Nov 3, 2005 10:52 PM
Reply to this message Reply
Indent your code and eclose it in the Java Tags so
we can actually read it...

> Hi..
> I am new to servlets . My first program executed..
> but the second one is having problem as all is going right
> but when i submit the uid and pwd through the html i get a
> blank page.it shows nothing.
>
>
> Servlet Code:
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import java.sql.*;
>
>
> public class login extends HttpServlet
> {
> public void doGet(HttpServletRequest
> req,HttpServletResponse res) throws
> ServletException,IOException
> {
> String uid=req.getParameter("t1");
> String pwd=req.getParameter("t2");
>
> PrintWriter out=res.getWriter();
>
> res.setContentType("text/html");
>
> try
> {
> Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
> Connection con=DriverManager.getConnection("jdbc :
> odbc:ms","scott","tiger");
>

Ensure the name of the column is correct, i.e. your
table must have the columns uid1 and pwd
as defined in your select statement.

> PreparedStatement psm=con.prepareStatement("select * from
> reg where uid1=? and pwd=?");

> psm.setString(1,uid);
> psm.setString(1,pwd);
//  because it replaces question mark 1 in the select
//  statment above. 
psm.setString(1, uid);
//  because it replaces question mark 2 in the select
//  statemtnt
psm.setString(2, pwd);

The rest seems OK, run those changes they should work
if everything mentioned has been satisfied else get back
here, and we'll try to figure it out. Also if you are
running a test on a mozilla-based browser you may
print out the errors it gives to the Java Console
under the menu option Tools. If you post that error
on the forum it will help us determine what the beef
is with your web-app.

> ResultSet rs=psm.executeQuery();
> if(rs.next())
> {
> out.println("<html><head><title>WELCOME</title></hea d>");
> out.println("<body><b><i>Hello user "+uid+"</b></i>");
> out.println("</body></html>");
> }
> else
> res.sendRedirect("http://localhost:8080/login.html");
> }
> catch(Exception e)
> {
> e.printStackTrace();}
> }
> }
>
> plz help me out ...
> thanks .

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Servlet Query! Posted: Nov 3, 2005 10:53 PM
Reply to this message Reply
Just some pent up frustration, I hate web-apps...

Flat View: This topic has 2 replies on 1 page
Topic: Arrays & Methods Previous Topic   Next Topic Topic: im thining to add video to my site something like that maybe www.cast-tv.co

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use