• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How to use the ShowView Action?

 
Bartender
Posts: 1973
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to have a JSP displayed that's below the WEB-INF folder based on a "failure" action. I understand, now, that I need to front "forwards" to a JSP below the WEB-INF by an action.

I was told that the ShowView action is the way to do get to JSP pages below WEB-INF, but I can't find a decent example of how to use it.

Can somebody explain what I need to do or give me a simple example?

Thanks.

Mike
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've never heard of a "ShowView" action. I just did a quick check of the javaDoc, and didn't find it there, either.

The best way to display a JSP without any processing beforehand is to create a "forward action mapping". This is an action mapping that does not require you to write an Action class. You just specify which JSP to forward to like this:

<action path="/myAction" forward="/WEB-INF/jsp/myPage.jsp">
 
Mike London
Bartender
Posts: 1973
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I do something like you're referring to, I get the error that the resource is not found (the JSP is under WEB-INF).

<action
. <!-- success action here -->
.
.
<forward name="failure"
redirect="true"
path="/WEB-INF/jsp/jspTest.jsp"/>
</action>

If I remove the redirect="true", it works with the current page (the current page displays the JSP text from the JSP page I want to forward to).

However, with the redirect="true" I get the message that the resource isn't found. The URL line and Tomcat error (JBOSS) all look correct.

So, my basic problem seems to be that when I return "failure" from an action class, I don't seem to know how to forward to a simple JSP page that's under WEB-INF.

Look foward to your reply.

Mike
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you specify redirect="true", you're telling the forward to send a message back to the browser to redirect to the URL specified. Since your JSP is in /WEB-INF, it isn't directly accessible to the browser, so that's why you get the message. The solution: remove redirect="true" from the forward.
 
Mike London
Bartender
Posts: 1973
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But, I want to go to another JSP!

I understand that going to a page under WEB-INF means that you need to have the forward "fronted" by an action.

The thing is, I can't seem to figure out how to make that work.

Help!!!

Mike
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mike,

If you specify the following, the jspTest.jsp will be displayed when you call the URL http://myserver.com/myApp/test.do. This is done without writing an Action class.

<action path="/test" forward="/WEB-INF/jsp/jspTest.jsp" />

Furthermore, if you specify the following forward with any other action, it will be successful:

<forward name="failure"
path="/WEB-INF/jsp/jspTest.jsp"/>


If you specify a forward without redirect=true, Struts uses the ServletContext's RequestDispatcher to forward the request to the specified JSP. The RequestDispatcher does have access to files inside the /WEB-INF directory, so it can display the JSP with no problems.

If you put redirect=true in a forward, it uses the sendRedirect() method on your HttpServletResponse object, which simply sends a message back to the browser to redirect to another URL. Since the /WEB-INF directory is protected from any access by the browser, you will get an error message if you try to redirect to any page under the /WEB_INF directory.

Is this making sense now?
[ May 05, 2006: Message edited by: Merrill Higginson ]
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If I remove the redirect="true", it works with the current page (the current page displays the JSP text from the JSP page I want to forward to).



Sorry, I didn't notice this statment before.

I think you are being confused by what is showing up in the URL. If you have an action (myAction.do) that can forward to either success.jsp or failure.jsp, the URL that you will see in your browser will still be http://myserver.com/myApp/myAction.do regardless of which page you forward to. The RequestDispatcher hides the forward and does not include it in the URL shown in the browser. However, it does successfully forward to the page.

After all, hiding the JSP file and making it inaccessible directly to the user is the whole reason for putting it inside the /WEB-INF directory in the first place.

If the above behavior is not what you want, the solution is simple: Take your JSPs out of the /WEB-INF directory. Then you can use redirect=true all you want, and the URL will always show which JSP is being displayed.
[ May 05, 2006: Message edited by: Merrill Higginson ]
 
Mike London
Bartender
Posts: 1973
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're terrific!!!

THANK YOU!!!

Yes, it was the redirect=true that was messing me up.

Thanks again!!!

Mike
 
Creativity is allowing yourself to make mistakes; art is knowing which ones to keep. Keep this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic