Advertisement

11.27.2007 at 09:31AM PST, ID: 22985496
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

How to get the current JSP PageContext from an Action with Struts

Tags: get, jsp, struts, pagecontext, current
Hi Experts!

I've been struggling with this seemingly easy question for some time now. Maybe my question is wrong, because what I am actually after is how to do a RequestUtils.computerUrl(). In the (very) old Struts 1.0.2, which I am unfortunately bound to during the current change in a legacy application, it seems about the only trustworthy way to calculate the absolute URL for doing a redirect action, based on an ActionForward.

I hope I am not too vague. I need to construct a URL, either absolute or relative to the current page context, based on an ActionForward, with a Map of parameters. I was construction the URL by hand, but found out that it is erroneous, because the current path is not known and the context path (to which the ActionForward is relative) is not known either.

The computeUrl() method requires as first parameter (whoever knows why) a  PageContext. I can store the current pageContext from the JSP file, but then I violate the MVC pattern (apart from being annoying).

I have found the JspFactory.getPageContext(), but that is used for initializing the page context, which is obviously not what I need here. Something like a static method of PageContext.getCurrentContext() I haven't yet found. I saw some references on the internet and some unanswered questions, none provided an answer. Though it shouldn't be too hard in a context-central environment to retrieve the context, shouldn't it?

For what it's worth, I use IBM WebSphere 5.1.1, which runs on JDK 1.4, with Struts 1.0.2 (yes, I know, it is old).

I am not looking for an answer for how to concatenate the different pieces of the URL, I can do that much myself, I'm after a stable distributable method that will construct the URL correctly using an ActionForward as a reference.

Thanks in advance,
-- Abel --

PS: I'm rather acquainted with newer JSP, JSTL, J2EE, Struts 2 etc, I've never worked with the ancient Struts 1.0.2 before, maybe it was just not provided for yet?
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: abel
Solution Provided By: boonleng
Participating Experts: 1
Solution Grade: A
Views: 178
Translate:
Loading Advertisement...
11.28.2007 at 02:09AM PST, ID: 20364318

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.28.2007 at 02:36AM PST, ID: 20364442

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.28.2007 at 04:41AM PST, ID: 20365013

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.29.2007 at 12:07AM PST, ID: 20372009

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.30.2007 at 03:21AM PST, ID: 20380984

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
12.06.2007 at 02:51AM PST, ID: 20418604

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
11.28.2007 at 02:09AM PST, ID: 20364318

Rank: Guru

If not mistaken, the method RequestUtils.computerUrl() is designed for struts tag, and not for action class,
coz this method has moved to TagUtils in later version.

What I suggest is that you base on the RequestUtils.computerUrl() source code to write a similar method like
CutomRequestUtils.computeURL(ServletContext context, HttpServletRequest request, ActionForward forward, Map params)

coz the PageContext is mainly use for retrieving the ServletContext and HttpRequest.
 
11.28.2007 at 02:36AM PST, ID: 20364442
So, basically what you are suggesting is doing it by hand (or, based on the open source of the current computeUrl() method).

In a way, it should be enough to have an ActionForward and the ServletContext or HttpServletRequest  (to find the root of the servlet) to find the absolute url for a forward. I am surprised there is no programmatic way to do so.

Do you know of a helper method that does this for me, including merging the params Map?
 
11.28.2007 at 04:41AM PST, ID: 20365013
What I have is the situation that in a legacy application a couple of JSP files exist that must be forwarded (redirected) when a certain requirement is met. The requirement (a state) is stored in the session.

Some JSP have a Struts Action. Hence I wanted to use the existing MVC pattern and not break it.

However, I the non-form JSP files need to be redirected sometimes too. I'd like to have it configurable and I hoped to use the struts-config for it. Is it possible to add an action that does nothing, except redirect or show the JSP page? Or am I making things to hard and should I just break the MVC pattern?

any help or thoughts is appreciated,

Cheers,
-- Abel --
 
11.29.2007 at 12:07AM PST, ID: 20372009

Rank: Guru

> Do you know of a helper method that does this for me, including merging the params Map?
Not that i know of, the generate path, merging of params.. etc are all done inside the method computeUrl().

> Is it possible to add an action that does nothing, except redirect or show the JSP page?
Yes. you can create a dummy action and configure the <foward  redirect="true"...> on the action.
Or just extend ForwardAction(http://struts.apache.org/1.0.2/api/org/apache/struts/actions/ForwardAction.html) and set redirect to true on the returned ActionForward.
But why not just use ForwardAction which forward to the jsp?
Accepted Solution
 
11.30.2007 at 03:21AM PST, ID: 20380984
To answer your last question: sometimes the moment of redirection is from a JSP and sometimes it is from an Action. Sometimes the location is at the root of the service (context) and sometimes it is at some arbitrary depth (several folders deep). The hostname can be different, too.

The largest problem (in lieu of the above) was that sometimes the redirect was internal (ActionForward) and sometimes it was external (response.sendRedirect). To add to the confusion, the whole application is build on a staggering 13 (!) frames and framesets that have inter-relations that will make your head spin.

That's the legacy. I hoped to find one-size-fits-all solution, hence the trying of either getting the servlet context and/or the JSP it is all coming from to build the redirection url. This was leading to only more spaghetti in the end: trying to keep within the bounds of Struts in an application that already violates it on many places proved to be largely impossible.

Making structure from a mess is hard (try to build a house from a ruin is harder than building a house from scratch) but I am not allowed to rebuild (budget and other reasons). Meaning that in the end I end up placing a new window every here and there.... :S

My best-fit solution so far (I have tried three extensible approaches) is to use a dedicated page that mimics some of the frame-behavior of existing pages. As it starts to look now, it may be the correct approach.

Thanks for the help so far,

Cheers,
-- Abel --
 
12.06.2007 at 02:51AM PST, ID: 20418604
Ok, by now I have found a couple of other workarounds to this. Basically, I use the HttpServletRequest object to store and retrieve the values and I changed the code such that I do not need the JspContext anymore (bad practice, it seemed now that I understand more of this codebase).

Because you've been the only one around that has helped me out, I'll grand you the points.
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628