Forums Register Login

Checking for nulls in JSP if user bypasses struts

+Pie Number of slices to send: Send
Hi all. Let me simplify the problem I'm thinking of and offer a small example. Say I have a struts action that happens when a user clicks a link on my site. The action fills a resultset and some other variables related to paging and such. These variables are stuck in the request and passed to the jsp page using struts. The jsp page then loops through the result set, prints the data, and then prints all the info for paging from the variables in the request.
So, my question, is what if the user bypasses the links on the site and entered in the browser mysite.com/results.jsp - and the action didn't run so there are no variables in the request? If every variable isn't checked for null, then the page will error out. What is the correct way to program for this?

Thanks!
+Pie Number of slices to send: Send
If you place your JSP pages in a folder hierarchy under WEB-INF, they will not be able to be addressed directly via URL and can only be invoked by server-side resources (such as your actions).
+Pie Number of slices to send: Send
Really? Can you explain more about this, so i feel comfortable with making the change?

I'm using Websphere Studio developer for development, and I see that I have all my pages in a folder called pages which is under a folder called Webcontent.
In the WEB-INF folder (which is under the webcontent folder also), there are 3 folders - classes, lib and src, and then there are some truts files and xml files.

Is this a Best Practice (putting the pages in the WEB-INF) folder? Or should I be doing something else in the code, and this is just a workaround.

Thanks for your help!
+Pie Number of slices to send: Send
Yes, it is considered a best practice as it prevents just the problems you are describing.
+Pie Number of slices to send: Send
What about files such as the login.jsp page, and other pages that have links going directly to them (they aren't action forwarded)?

If an action calls a global forward to a jsp in the webinf directory, that will work?

do those actually have to be spereated out and left outside of the webinf folder?
+Pie Number of slices to send: Send
Any JSP that should not be addressed via URL should be hidden under WEB-INF. These files are accesible via the forwarding mechanisms of any other resource. JSP files that need to be directly addressable via URL (I usually have few to none) should be outside of the WEB-INF folder.
+Pie Number of slices to send: Send
Ok, very useful to know. One last question to clarify.

I have a main page. Let's call it mainpage.jsp. On the left it has a list of links. All the links on this main.jsp page are done like this:

<html:link styleClass = "left-nav" style = "left-nav" forward="submit" >Submit Content</html:link></td>

Some of these html:links will go to the global forward and be jsp pages and some will be actions (.do).

As an example there is one link that is called Education. If I hold my mouse over it on the mainpage.jsp i can see that the link is .....jsp whereas the others are .....do

So, even though this is a link that was rendered from a global forward, when the user clicks on it it is still going directly to the jsp right? And that means that it wouldn't work if it was in the web-inf directory?

Thanks for helping me clear this up. I'm sure when someone else is searching for these answers next time, this thread will help them out.
+Pie Number of slices to send: Send
That is correct. What your Struts tags look like is completely moot. All that matters is what HTML is sent to the browser. If the link ends up being a direct access to the JSP, that JSP cannot be hidden.
permaculture is largely about replacing oil with people. And one tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1050 times.
Similar Threads
Can't perform logic on my bean class getter methods
session variables in struts
Problem with Servlet Context
Struts understanding
GWT + mvp4g url-rewriting
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:36:37.