• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

linking to a jsp page instead of linking to an action

 
Sammy Bill
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The *browser* is not able to access resources under WEB-INF. The *server* can.
 
Sammy Bill
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...

No. The browser is accessing the action URL. The *server* is accessing the JSP.
 
Sammy Bill
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, okay; that makes more sense :)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic