forward servlet to jsp
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   hermoinee_harris
Posted On:   Monday, May 17, 2004 09:20 PM

-------clerkloginservlet.java------------------------ import java.io.*; import java.sql.*; import javax.sql.*; import java.util.*; import java.sql.SQLException; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.ServletException; public class clerkloginServlet extends HttpServlet{ public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String name=req.getParameter("id"); String pswd=req.getParameter("pswd");    More>>


-------clerkloginservlet.java------------------------

import java.io.*;

import java.sql.*;

import javax.sql.*;

import java.util.*;

import java.sql.SQLException;

import javax.servlet.*;

import javax.servlet.http.*;

import javax.servlet.ServletException;



public class clerkloginServlet extends HttpServlet{

public void doGet(HttpServletRequest req,

HttpServletResponse res)

throws ServletException, IOException {


String name=req.getParameter("id");

String pswd=req.getParameter("pswd");



Connection con = null;

Statement stmt = null;

ResultSet rs = null;


try {

Class.forName("com.mysql.jdbc.Driver");

con = DriverManager.getConnection("jdbc:mysql://localhost/"+"CUBA1?user=root&pasword=");

stmt = con.createStatement();

rs = stmt.executeQuery("SELECT * FROM CUBA1.clerk_login");


if(name == null)

{

RequestDispatcher rd = getServletContext().getRequestDispatcher("/password_wrong.jsp");

}

else

{

if(pswd!=null)

{

RequestDispatcher rd = getServletContext().getRequestDispatcher("/clerk_pg.jsp");

}}


} //end try

catch (SQLException e) {

throw new ServletException("Servlet Could not display records.", e);

} //end catch

catch (ClassNotFoundException e) {

throw new ServletException("JDBC Driver not found.", e);

}//end catch

finally {

try {

if(rs != null) {

rs.close();

rs = null;

}

if(stmt != null) {

stmt.close();

stmt = null;

}

if(con != null) {

con.close();

con = null;

}

} //end try

catch (SQLException e) {}

} //end finally

} //end post

} //end class


------clerk_signin.jsp------------------------


action="http://localhost:8080/examples/servlet/clerkloginServlet2"

method="get">




problem : i've compile clerkloginServlet.java in

./javac -classpath /root/tomcat/common/lib/servlet.jar

/root/tomcat/webapps/examples/WEB-INF/classes/clerkloginServlet.java.

there is no error was detected


clerk_signin.jsp->clerkloginServlet


if (true)

clerk_pg.jsp


else (false)

pasword_wrong.jsp


when i run the clerk_signin.jsp it should go to clerkloginServlet and if the id is true it will go to clerk_pg.jsp or if false it go to password_wrong.jsp.

the problem i'm facing here is after clerkloginServlet it appears blank screen.

So anyone have any idea in solving this problem...please..i beg u....i've to finish it by this friday...

   <<Less

Re: forward servlet to jsp

Posted By:   Christopher_Koenigsberg  
Posted On:   Tuesday, May 18, 2004 09:23 AM

For one thing, seems you aren't handling the case where "name" is not null, but "pswd" IS null?

About | Sitemap | Contact