importing the request object into a bean - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

importing the request object into a bean

hi folks,

I'm working my way through a 21 day jsp course and I'm trying to solve this problem:
"Create a new javabean and pass the request object to a method of that bean (this object is an object of the Java javax.servlet.http.HttpServletRequest class). Using the request.getParameter method, recover some text from a text field and pass it back to a JSP page using another method, and display that text."

Right - so i make my bean but I'm stuck on how to pass the request object into it - here was one solution i tried - it didnt work and i have no idea why! Could someone please tell me what I'm doing wrong?

Yours in desperation,

Fuzzgig

package beans;

class ch06ex1
{

String message;

ch06ex1()
{
}

javax.servlet.http.HttpServletRequest request;

void setMsg () throws java.io.IOException
{
message = request.getParameter("text1");
}

String getMessage()
{
return this.message;
}
}

The jsp page that requests the bean is as follows:



ch6 exercise 1 jsp output page


>h1>ch6 exercise 1 jsp output page


The text you input was:




The html page that starts it all off is as follows:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">



ch6 exercise 1 input page

ch6 exercise 1 input page









Comments

  • treshrtreshr Posts: 326Member
    As you know, you JSP page has got a request object when you call it.

    Know you only have to define a variabele that instantiates the HttpServletRequest class in your bean like this:
    [code]
    HttpServletRequest req;
    [/code]

    Know make a get and set method for the variabel like this:
    [code]
    public HttpServletRequest getReq(){
    return req;
    }

    public void setReq(HttpServletRequest req){
    this.req = req;
    }
    [/code]

    This is a easy way to do it.
    Hope I helped you enouph, success.

    --=][tReShR][=--

  • fuzzgig49fuzzgig49 Posts: 13Member
    Thanks TreshR,

    I'm not up to custom tags yet - is that what the [code] [/code] is referring to? And do I need to import the HttpServletRequest class at the start of the bean as well?

    Thanks,

    Joel

    : As you know, you JSP page has got a request object when you call it.
    :
    : Know you only have to define a variabele that instantiates the HttpServletRequest class in your bean like this:
    : [code]
    : HttpServletRequest req;
    : [/code]
    :
    : Know make a get and set method for the variabel like this:
    : [code]
    : public HttpServletRequest getReq(){
    : return req;
    : }
    :
    : public void setReq(HttpServletRequest req){
    : this.req = req;
    : }
    : [/code]
    :
    : This is a easy way to do it.
    : Hope I helped you enouph, success.
    :
    : --=][tReShR][=--
    :
    :

Sign In or Register to comment.