aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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
Author

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.
Arun


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)


!_I_Know_Kung_Fu_!
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
<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>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why the code works in GET and not in POST?
 
Similar Threads
Excel Window problem
difference btw doGet and doPost methods?
get() method And post() method?
Problem in JSP compilation
how to use file chooser in jsp