This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Servlets and the fly likes Servlet Query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Query" Watch "Servlet Query" New topic

Servlet Query

Monisha Kapur

Joined: Oct 30, 2005
Posts: 1
I am new to servlets . My first program executed..
but the second one is having problem as all is going right but when the i submit the uid and pwd through the html i get a blank shows nothing

Servlet Code:
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();


Connection con=DriverManager.getConnection("jdbc dbc:ms","scott","tiger");

PreparedStatement psm=con.prepareStatement("select * from reg where uid1=? and pwd=?");
ResultSet rs=psm.executeQuery();
out.println("<body><b><i>Hello user "+uid+"</b></i>");
else res.sendRedirect("http://localhost:8080/login.html");
catch(Exception e)

plz help me out ...
thanks .
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
I would first verify that the parameters are populated before using them in a query.

String uid=req.getParameter("t1");
String pwd=req.getParameter("t2");

if(your uid and pw fields != null && their length is > 0)
do what ever

Also, thee is a chance that no rows were returned. You need to display something if no rows were found.

So much trouble in the world -- Bob Marley
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13026
You should also take the precaution of closing the output stream to force flushing of the contents. A simple out.close() will do the trick.
Eddy Lee Sin Ti
Ranch Hand

Joined: Oct 06, 2005
Posts: 135
Any stack trace output in the console?

SCJP, SCWCD, SCJWS, IBM 700,IBM 701, IBM 704, IBM 705, CA Clarity Technical<br /> <br /><a href="" target="_blank" rel="nofollow"></a>
It is sorta covered in the JavaRanch Style Guide.
subject: Servlet Query
It's not a secret anymore!