• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why the code works in GET and not in POST?

 
Arun, Shanmugham
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Arun
 
Andrew Shafer
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, its not in JSP , its in Servlet.
Here is my code of Servlet
<CODE>
public class SiteFeedback extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
doPost(req,res);
}
public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
{
res.setContentType("text/html");
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="Like";
else
Like="Don't Like";
if(Friendly.equals("Yes"))
Friendly="User Friendly";
else
Friendly="Not User Friendly";
if(Download.equals("Fast"))
Download="Fast";
else
Download="Slow";
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();
props.put("mail.smtp.host","mail.seeconsulting.com");
Session session=Session.getDefaultInstance(props,null);
try
{
..........
..........
</CODE>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic