This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

post request from jsp not received by Servlet

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have not implemented doPost() properly, it cannot have HttpSession as an argument.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya... how cud i b so so carelsss to overlook it .. thanks u both...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic