• Post Reply Bookmark Topic Watch Topic
  • New Topic

Checking for nulls in JSP if user bypasses struts

 
Claude Forkner
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Claude Forkner
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it is considered a best practice as it prevents just the problems you are describing.
 
Claude Forkner
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Claude Forkner
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!