Servlet - accpeting request parameters

Posted on 2003-03-04
Medium Priority
Last Modified: 2013-11-24
I am trying to pull a parameter off of a url to use it inside a query.  How can I refrence this inside the servlet?
Question by:programmer13
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
LVL 35

Expert Comment

ID: 8064947
httpServletRequest.getParameter( "Nameofparameter" ) ;
LVL 35

Expert Comment

ID: 8064950
assuming you're inside a doGet() or doPut()
LVL 35

Expert Comment

ID: 8064967
say your servlet got called by :


then if inside your doGet(), you had:


Object o = httpServletRequest.getParameter( "woo" ) ;
if( o == null )
  System.out.println( "NO WOO!!" ) ;
  System.out.println( (String)o ) ;


The servlet would print out "yay"


Is this what you meant?
LVL 35

Accepted Solution

TimYates earned 2000 total points
ID: 8065019
Hehehe...more detail (as you posted so many points, and I'm bored at work ;-)


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

public class MyDaftServlet extends HttpServlet {
  public void doGet(HttpServletRequest request,                    HttpServletResponse response) throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    out.print( "<HTML><BODY>");
    out.print( request.getParameter("woo") ) ;
    out.print( "</BODY></HTML>");

  public void doPost(HttpServletRequest request,
                     HttpServletResponse response)
      throws ServletException, IOException {
    doGet(request, response);




would give you an HTML page with "yay" on it :-)

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses
Course of the Month13 days, 3 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question