File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Passing redirect from bean class to JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Passing redirect from bean class to JSP" Watch "Passing redirect from bean class to JSP" New topic
Author

Passing redirect from bean class to JSP

Nick Davenport
Greenhorn

Joined: Jul 27, 2007
Posts: 12
I would like to create a JavaBean (in Tomcat 4.1.3) that can pass the response.sendRedirect() to a JSP where the JSP will actually take that response.sendRedirect() method and redirect the page but cant figure out how to do it in the JavaBean class. The redirect would only happen if a condition was met in my JavaBean class:



JSP called main.jsp

[ July 29, 2007: Message edited by: Nick Davenport ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

Check the API for sendRedirect(). What does it return?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Nick Davenport
Greenhorn

Joined: Jul 27, 2007
Posts: 12
I finally have a redirect from a bean working in the JSP using Java Bean and jsp:useBean tag.

Everything works great and now I was just wondering how I can eliminate the scriptlet part (<% redir.RedirectPage(response); %>) and put it into a useBean tag? I dont have any access to JSTL due to strict environment I work in so I want to get this working with useBean tag if possible.




Bean


[ July 31, 2007: Message edited by: Nick Davenport ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

Originally posted by Nick Davenport:
I dont have any access to JSTL due to strict environment I work in ...


Wait a minute... the powers that be want you to eliminate scriplets from the page, yet will not allow use of the JSTL and EL?

If so, that is the most moronic thing I've heard this year. Please tell me it isn't so!
[ July 31, 2007: Message edited by: Bear Bibeault ]
Nick Davenport
Greenhorn

Joined: Jul 27, 2007
Posts: 12
100% true and it will take about another 6 months or more before I can get it (JSTL) approved with paperwork etc.

Any advise on how I can get this to work now without JSTL because I want a scriptlet free JSP.

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

I can't tell from what you said if your are prohibited from using scriplets, or just don't want to. Which is it?

If the latter, much as I feel that scriplets should be stricken from the memory of every JSP developer, I'd give it up until you can use the JSTL. A JSP without either of scriplets or JSTL can't do very much.

You will be limited to just what you can do with the JSP standard actions. And trying to twist those to do things that they were not intended to do will cause more harm and confusion than scriplets do.
Nick Davenport
Greenhorn

Joined: Jul 27, 2007
Posts: 12
Thanks for information.


I can't tell from what you said if your are prohibited from using scriplets, or just don't want to. Which is it?


I can use scriplets but want to get into the practice of not using them and it could be a long long time before I get JSTL. I was hoping to get it to work and improve my javabean skills.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

But any "practice" you would get would be less than useful since it would not be practice in the real way that scriptless JSP should be written.

You can increase your "bean skills" without resorting to using them in artificial manners.

Here are some suggestions for getting some practice in writing scriptless pages even while still using scriplets:

  • Be sure that all processing is done in the servlet controller.
  • When accessing beans, only call methods that adhere to the propety pattern: for example getXyz() with no parameters.
  • Use scriplets only for things like for-loops and conditionals. Don't perform any processing that you could not do with the JSTL.

  • [ July 31, 2007: Message edited by: Bear Bibeault ]
    Ben Souther
    Sheriff

    Joined: Dec 11, 2004
    Posts: 13410

    Are you allowed to write your own custom tags?

    The app I work on was 100% scriptlet free well before JSTL and EL were out.
    A handful of custom tags and some data structures on the back end to go with them made it possible. We're currently in the process of switching it over to JSTL and EL to standardize things.

    For your original issue...
    The decision to redirect or not should be made before the request ever reaches the JSP.


    Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 60780
        
      65

    Originally posted by Ben Souther:
    Are you allowed to write your own custom tags?


    Not to make light of the OP's situation, but I would actually find it a hoot if custom tags were allowed but the JSTL was not!
    Ben Souther
    Sheriff

    Joined: Dec 11, 2004
    Posts: 13410

    It wouldn't surprise me.
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: Passing redirect from bean class to JSP
     
    Similar Threads
    JSP - UseBean
    Urgent: How to use Indexed Properties
    Problem with jsp:getProperty
    Java Beans
    import package problems??