File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes post request from jsp not received by Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "post request from jsp not received by Servlet" Watch "post request from jsp not received by Servlet" New topic
Author

post request from jsp not received by Servlet

Akash Bhatt
Greenhorn

Joined: Jul 26, 2005
Posts: 25
My servlet is not able to receive a post request from a jsp. This servlet is a load on start servlet. What could be the reason?
Code of JSP:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="stylesheet" type="text/css">
<TITLE>index.jsp</TITLE>
</HEAD>
<BODY>
<form action="/prologWAR/ProLogServlet" method="post">

<Table>
<TR>
<TD>Enter ID</TD>
<TD><INPUT type="text" name="id" size="20"></TD>
</TR>
<TR>
<TD>Enter Password</TD>
<TD><INPUT type="password" name="passwd" size="20"></TD>
</TR>
<TR>
<TD colspan="2">
<INPUT type="submit" name="sbmt" value="Submit">
</TD>
</TR>
</TABLE>

</form>

</BODY>
</HTML>


Code Of Servlet:


package prolog.servlets;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;

import javax.naming.NamingException;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import prolog.DAO.LoginInfoDAO;

/**
* @version 1.0
* @author
*/
public class ProLogServlet extends HttpServlet implements Servlet {

/**
* @see javax.servlet.GenericServlet#void ()
*/
public void destroy() {

super.destroy();

}


private void requestDispatch(
ServletContext ctx,
HttpServletRequest req,
HttpServletResponse resp,
String page)throws ServletException, IOException {
ctx.getRequestDispatcher(page).forward(req, resp);

}

public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
System.out.println("In doget");

}

/**
* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public void doPost(HttpServletRequest req, HttpServletResponse resp,HttpSession session)
throws ServletException, IOException {
System.out.println("In doPost");
try{

String Id = req.getParameter("id");
String Passwd = req.getParameter("passwd");
String DBPasswd = LoginInfoDAO.getPass(Id);
if(Passwd.equals(DBPasswd)){
session.setAttribute("res","Login Succeds");
}else{
session.setAttribute("res","Login Fails");
}
requestDispatch(getServletConfig().getServletContext(),req,resp,"index.jsp");
}catch(NamingException ne){
System.out.println(ne.getExplanation());
session.setAttribute("errorflag",ne.getExplanation());
}catch(SQLException sq){
System.out.println(sq.getErrorCode()+" "+sq.getSQLState()+" "+sq.getLocalizedMessage());
session.setAttribute("errorflag",sq.getErrorCode()+" "+sq.getSQLState()+" "+sq.getLocalizedMessage());
}catch(Exception e){
System.out.println(e.getMessage());
session.setAttribute("errorflag",e.getMessage());
}
}



}
package prolog.servlets;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;

import javax.naming.NamingException;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import prolog.DAO.LoginInfoDAO;

/**
* @version 1.0
* @author
*/
public class ProLogServlet extends HttpServlet implements Servlet {

/**
* @see javax.servlet.GenericServlet#void ()
*/
public void destroy() {

super.destroy();

}


private void requestDispatch(
ServletContext ctx,
HttpServletRequest req,
HttpServletResponse resp,
String page)throws ServletException, IOException {
ctx.getRequestDispatcher(page).forward(req, resp);

}

public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
System.out.println("In doget");

}

/**
* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public void doPost(HttpServletRequest req, HttpServletResponse resp,HttpSession session)
throws ServletException, IOException {
System.out.println("In doPost");
try{

String Id = req.getParameter("id");
String Passwd = req.getParameter("passwd");
String DBPasswd = "xyz";
if(Passwd.equals(DBPasswd)){
session.setAttribute("res","Login Succeds");
}else{
session.setAttribute("res","Login Fails");
}
requestDispatch(getServletConfig().getServletContext(),req,resp,"index.jsp");
}catch(NamingException ne){
System.out.println(ne.getExplanation());
session.setAttribute("errorflag",ne.getExplanation());
}catch(SQLException sq){
System.out.println(sq.getErrorCode()+" "+sq.getSQLState()+" "+sq.getLocalizedMessage());
session.setAttribute("errorflag",sq.getErrorCode()+" "+sq.getSQLState()+" "+sq.getLocalizedMessage());
}catch(Exception e){
System.out.println(e.getMessage());
session.setAttribute("errorflag",e.getMessage());
}
}



}


Code only checks for the password.


...ToucH SkieS
AKASH
SCJP 1.4 86%
SCWCD 1.4 82%
Selvaraj Subramanian
Ranch Hand

Joined: Jul 15, 2005
Posts: 37
You have not implemented doPost() properly, it cannot have HttpSession as an argument.


Selvaraj.S<br />SCJP 1.4 -83%<br />SCWCD 1.4 - 85%<br />SCEA 4 Part 1(310-051) - 89%
Manish Agarwal
Greenhorn

Joined: Jan 30, 2006
Posts: 20
correct implimentation of doPost is
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException{
}


SCWCD1.4, SCJP1.4, OCA 9i
Akash Bhatt
Greenhorn

Joined: Jul 26, 2005
Posts: 25
Ya... how cud i b so so carelsss to overlook it .. thanks u both...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: post request from jsp not received by Servlet