jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes Why the code works in GET and not in POST? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Why the code works in GET and not in POST?" Watch "Why the code works in GET and not in POST?" New topic

Why the code works in GET and not in POST?

Arun, Shanmugham
Ranch Hand

Joined: Apr 05, 2001
Posts: 34
We have done a flash screen which is used for data entry and the data is sent to JSP url. Here the JSP code is written in a way to handle POST method. But the output is "NullPointer Exception" when the method is set as POST. But the same is working if it is changed to GET.
Can anyone tell me y.

Sun Certified Programmer for Java2 Platform
Andrew Shafer
Ranch Hand

Joined: Jan 19, 2001
Posts: 338

Hmm, show us code.
JSP should implicitly handle both GET and POST. You don't need to write it to handle POST or GET. (unless you want it to do something different for each one)

manav kher
Ranch Hand

Joined: Nov 21, 2000
Posts: 98
well GET as you know is done through url encoding, so if the data being submitted is not being POST-ed then doPost() will not work and that i guess is what you are implementing.
Arun, Shanmugham
Ranch Hand

Joined: Apr 05, 2001
Posts: 34
Sorry, its not in JSP , its in Servlet.
Here is my code of Servlet
public class SiteFeedback extends HttpServlet
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
PrintWriter out=res.getWriter();
String Name=req.getParameter("Name");
String EMail=req.getParameter("EMail");
String Like=req.getParameter("Like");
String Friendly=req.getParameter("Friendly");
String Download=req.getParameter("Download");
String Comments=req.getParameter("Comments");
String Rating=req.getParameter("Rating");
if (Like.equals("Yes"))
Like="Don't Like";
Friendly="User Friendly";
Friendly="Not User Friendly";
String MsgBody="Hi, I am " + Name + ", and I visited your site at www.seeconsulting.com." + " I would like to offer my comments about the site." + (char)13 + (char)13 + "The site is " + Friendly + " and the download is " + Download + ". " + (char)13 + "On the whole, I " + Like + " the site, with my overall rating being " + Rating + ". " +(char)13 + (char)13 + "Additionally my comments are " + Comments + ". " +(char)13 + (char)13 + "You can get back to me at this Id: " + EMail ;

Properties props=new Properties();
Session session=Session.getDefaultInstance(props,null);
I agree. Here's the link: http://aspose.com/file-tools
subject: Why the code works in GET and not in POST?
It's not a secret anymore!