• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with doGet and doPost methods

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I wrote a simple thing.Taking two textbox values and dispalying them .Any code i write in doget() and doPost() dont work,but in the processRequest() method it works.I can see the values in the url when i use GET.


 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
processRequest is not part of the Servlet API; what API are you using?
 
nvamsi naki
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think Servlet API.I dont know much about this.After seeing your comment ,i searched for what API is used in servlets.



i used these packages

javax.servlet.http.HttpServlet;
javax.servlet.http.HttpServletRequest;
javax.servlet.http.HttpServletResponse;

 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Servlet API has no such method; it must be in your code. Why don't you post what you have, and we may be able to point out what's going wrong.
 
nvamsi naki
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration;

@WebServlet(name = "validate", urlPatterns = {"/validate"})
public class validate extends HttpServlet {


protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {

out.println("<html>");
out.println("<head>");
out.println("<title>Servlet validate</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet validate at " + request.getContextPath () + "</h1>");
out.println("</body>");
out.println("</html>");

} finally {
out.close();
}
}

protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}


protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

processRequest(request, response);

}

public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code to the forums.

As processRequest() is a method you wrote in your code, how were we supposed to know anything about it?
 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi..Lifecycle of a servlet has 3 methods
(1)init()
(2)service()
(3)destroy()
Whatever main logic we have in servlet we write it in the service() method..........Now i think you are using the Netbeans IDE for writing servlets program..........Now in Netbeans IDE there is no service() method but an processRequest() method..............i.e. service() is equal to processRequest()...............
Now whatever method you have chosen to pass data i.e. Get or Post from these method the service() method is called............i.e. in Netbeans from the from the doGet() method and doPost() you can see a call given to processRequest() method (this you will find at the bottom of the code, while creating servlets)...............
You also said that when i write code in doGet() or doPost () it doesn't executes then you might be doing some mistake because i have tried this and it works
 
Rameshwar Soni
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are declaring the object "out" of PrintWriter 2 times once in processRequest() and once in doGet().......check it out
 
nvamsi naki
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Please UseCodeTags when posting code to the forums.

As processRequest() is a method you wrote in your code, how were we supposed to know anything about it?




sorry about that i changed it
 
nvamsi naki
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rameshwar Soni wrote:You are declaring the object "out" of PrintWriter 2 times once in processRequest() and once in doGet().......check it out




its working .i removed the PrintWriter in processRequest.


Thank you Rameshwar Soni,Bear Bibeault ,Ulf Dittmer
reply
    Bookmark Topic Watch Topic
  • New Topic