?
Solved

Servlet - accpeting request parameters

Posted on 2003-03-04
4
Medium Priority
?
159 Views
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?
0
Comment
Question by:programmer13
[X]
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
4 Comments
 
LVL 35

Expert Comment

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

Expert Comment

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

Expert Comment

by:TimYates
ID: 8064967
say your servlet got called by :

http://localhost/servlets/MyDaftServlet?woo=yay&foo=bar

then if inside your doGet(), you had:

--------------

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

--------------

The servlet would print out "yay"

:-)

Is this what you meant?
0
 
LVL 35

Accepted Solution

by:
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 {
    response.setContentType("text/html");
    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);
  }
}

--------------------------------------

Then

http://localhost/servlets/MyDaftServlet?woo=yay&foo=bar

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

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