permaculture playing cards*
The moose likes Struts and the fly likes linking to a jsp page instead of linking to an action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "linking to a jsp page instead of linking to an action" Watch "linking to a jsp page instead of linking to an action" New topic
Author

linking to a jsp page instead of linking to an action

Sammy Bill
Ranch Hand

Joined: Dec 29, 2008
Posts: 96
Hello,

I have a products.jsp page that displays the products stored in the database.

to get to that page, i have to click a link in the home page that says:

<a href="catalog.action">products</a>


then it will processes the action and call products.jsp.

but when i go directly to prducts.jsp by typing the url to the jsp page ( not the action), i get no products.
I understand that when i go to products.jsp directly, i m not callin the action.

is there anyway that i can have localhost:8080/proj/products.jsp call the action and return the result to the products.jsp
without typing localhost:8080/proj/catalog.action

Thanks
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


is there anyway that i can have localhost:8080/proj/products.jsp call the action and return the result to the products.jsp
without typing localhost:8080/proj/catalog.action


Why do you want to do that ? Check out Logic:redirect , if that could help you.
Also where did you place the jsp ( cannot be under WEB-INF)
Sammy Bill
Ranch Hand

Joined: Dec 29, 2008
Posts: 96
Balu Sadhasivam wrote:

is there anyway that i can have localhost:8080/proj/products.jsp call the action and return the result to the products.jsp
without typing localhost:8080/proj/catalog.action


Why do you want to do that ? Check out Logic:redirect , if that could help you.
Also where did you place the jsp ( cannot be under WEB-INF)


1) I want to allow the user to type the url localhost:8080/ProjName/products.jsp. and get the list of the products in the database.
The way i m doing it is through a link that will call the action then it will display the products.jsp page. so the user will have to click
a link to get to that page.

2) why I can not place the jsp file under WEB-INF, thats what i m doing

Thanks
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Files under WEB-INF are not available to the browser.

In general, Struts apps should always access their pages through actions and avoid mixing "plain" JSP addresses. I don't understand why you'd want to do that either, or what's wrong with just typing "products.do" (or, in your case, the longer "products.action"). What's it matter? Why complicate things?
Sammy Bill
Ranch Hand

Joined: Dec 29, 2008
Posts: 96
David Newton wrote:Files under WEB-INF are not available to the browser.

In general, Struts apps should always access their pages through actions and avoid mixing "plain" JSP addresses. I don't understand why you'd want to do that either, or what's wrong with just typing "products.do" (or, in your case, the longer "products.action"). What's it matter? Why complicate things?


Ok, I understand now.
but i m able to access jsp pages under WEB-INF
http://localhost:8080/Final_Project/catalog.action will actually take me to the product page???

Thanks

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The *browser* is not able to access resources under WEB-INF. The *server* can.
Sammy Bill
Ranch Hand

Joined: Dec 29, 2008
Posts: 96
David Newton wrote:The *browser* is not able to access resources under WEB-INF. The *server* can.


when i do http://localhost:8080/Final_Project/catalog.action.

isn't that accessing it through the browser?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

...

No. The browser is accessing the action URL. The *server* is accessing the JSP.
Sammy Bill
Ranch Hand

Joined: Dec 29, 2008
Posts: 96
David Newton wrote:...

No. The browser is accessing the action URL. The *server* is accessing the JSP.


Sorry If i m misunderstanding that last part.

When I do http://localhost:8080/Final_Project/login.jsp it works fine.
and when i do http://localhost:8080/Final_Project/catalog.action it works fine too.

so Why i m acessing the action URL and the JSP from WEB-INF.

Sorry, I might be overlooking the answer.

Thanks a lot for you time
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

In your JSP example URL the JSP isn't under WEB-INF.
In the action example URL the JSP *may* be under WEB-INF; I have no way of knowing.

The original point was that we didn't understand your requirement to use a JSP file as the URL (which in general you shouldn't do in a Struts app). The other point was that if a JSP is under WEB-INF the *browser* won't be able to access it directly.
Sammy Bill
Ranch Hand

Joined: Dec 29, 2008
Posts: 96
David Newton wrote:In your JSP example URL the JSP isn't under WEB-INF.


That is what I did not understand, I m sure the login.jsp is under WEB-INF. and i can access it directly.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You wrote:When I do http://localhost:8080/Final_Project/login.jsp it works fine.

That JSP is not under /WEB-INF. It's either in the root (if you're deploying to the "Final_Project" app context) or under /Final_Project if you're deploying to the root context.

You may *have* a login.jsp under /WEB-INF, but it's not the one being served when you use the above URL.
Sammy Bill
Ranch Hand

Joined: Dec 29, 2008
Posts: 96
David Newton wrote:
You wrote:When I do http://localhost:8080/Final_Project/login.jsp it works fine.

That JSP is not under /WEB-INF. It's either in the root (if you're deploying to the "Final_Project" app context) or under /Final_Project if you're deploying to the root context.

You may *have* a login.jsp under /WEB-INF, but it's not the one being served when you use the above URL.


Sorry, Execuse my stupidity.
For some unknown reason, I was meaning WebContent when i refer to /WEB-INF.

Thank you very much for the clarification and for you time :thumbup:
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Oh, okay; that makes more sense :)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: linking to a jsp page instead of linking to an action
 
Similar Threads
Tag Files and attributes
Struts 2 validation chaining
integration of struts- jsf Problem related t url
populate items using struts2 <s:select>
Changing the default Page in Tomcat