Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

post request from jsp not received by Servlet

 
Akash Bhatt
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Selvaraj Subramanian
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have not implemented doPost() properly, it cannot have HttpSession as an argument.
 
Manish Agarwal
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
correct implimentation of doPost is
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException{
}
 
Akash Bhatt
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya... how cud i b so so carelsss to overlook it .. thanks u both...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic