aspose file tools*
The moose likes JSP and the fly likes Getting a Request object from a Handler in JSPs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Getting a Request object from a Handler in JSPs" Watch "Getting a Request object from a Handler in JSPs" New topic
Author

Getting a Request object from a Handler in JSPs

Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 389
Hi Steve,

I have solved it. It was that Tomcat was no recompiling the *.jsp every time I changed it.

But now I have another doubt, I would prefer get the request from the handler instead that from the jsp(me don't like scriptlets in my jsp). Do you know what way retrieve the request from the handler?

Many Thanks,
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61653
    
  67

What handler?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Hi Angus,

Can you be more specific about what you are trying to do. From your other post I know you are trying to access the Request object from your own class. Previously you wanted to get it from the JSP, but now you have a 'handler' you want to use. What handler are you talking about?


Steve
Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 389
Hi,

well I was trying to get my URL from my *.jsp using a scriptlet like this:



and finally it worked well. But now instead of use a scriptlet I need clean my *.jsp from scriptlets. Then I would need get my request and send it to my class immediately before the *.jsp is displayed. I mean I want remove the scriptlet, and continue getting the request and sending it to my class.

I have talked with an architect he has told that there is a "handler", but I don't know more. I have searched in the internet and I have found things like "RequestHandler". But I have not figure out nothing about what way do the process.


Any idea?

Many Thanks,
Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 389
Hi,

I am trying send my request without the need of using scriplets, as I told you before. Now I am trying the next approach:

In my jsp:




and the method is in the class FetchingAuthToken I have included it this way:

<jsp:useBean id="myBean" scope="session" class="analyticsAccessToken.FetchingAuthToken" />:




When I run the app I find the next error:



Any idea?

Many Thanks





Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Angus Ferguson wrote:
I have talked with an architect he has told that there is a "handler", but I don't know more. I have searched in the internet and I have found things like "RequestHandler".

you need to ask him clearly what Handler it is.

and there is Tag Hendlers . but I am not sure, that is what you are looking.
Angus Ferguson wrote:
<c:out value="${myBean.sendRequest(request)}"

c:out is to display the values... and you can use c:set with target attribute. also your property should have valid setter/getter.
something like below


*but I do suggest you to use servlet instead of jsp.



Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 389
Hi,

I have applied your code like this:




But I get the next error:



Do it means that the request is empty? Any idea?

And after that what way could I retrieve my request from my class? Maybe using getAttribute?

Many Thanks
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Seethraman's code sample was this:

Your code sample is this:

And the error message is this:
Invalid property in <set>: "null"


Compare the code and look at the message. What do you think the problem is?
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

And after that what way could I retrieve my request from my class? Maybe using getAttribute?

No, as Seetharaman said, you need a setter method to receive the value, and a getter method to get the results.

I think you need to re-think the strategy here. I don't think you clearly understand the technology or tools you are using. JEE is not the same as JSE, there is a lot to learn. I suggest going through a good tutorial (such as this one) or a good book so that you understand what you are doing.
Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 389
Hi,

thanks from reply.

The error has gone.

My code in my jsp is:



and in my class the code is:




When I call my class I get null



Any idea?

Many thanks,
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

When you make that call, the request object is null. More than that is impossible to say because we don't see the code. Here are my guesses:

1) You do that call before you call setRequest()
2) You call setRequest() on a different instance of your class
Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 389
Hi Steve,

thanks I was calling the method to early. Now it works.

The last step I need to do is call a method from my jsp. Before was set now is a get.

I have checked that the code:



doesn't works because get is not a recognize tag, after that I have tried like this



but it is not recognize as a type also I have tried with the method getProperty() but no.

What more could I try?

Any idea?

Many Thanks,
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Like I said before, you need to learn more about the technology and how to use it. In addition to the JEE tutorial I pointed you to before, here is one specifically on JSTL: http://docs.oracle.com/javaee/1.4/tutorial/doc/JSTL3.html

I am not just pointing you to other resources to be short (I hope it doesn't come off as rude) I am doing so because these are big topics that have a lot of moving parts. If you don't learn them properly then you will have a lot of trouble. The forums are great for answering questions but they aren't the best place to learn things like this from scratch (it would take too long and require too much investment in time).
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Getting a Request object from a Handler in JSPs