I've been struggling with this issue as I'm new to Struts2 development, and just started using this naming Convention Plugin recently.
I'm trying to create a simple webapp which at first will only consist in two pages:
- Login page (
login.jsp
)
- Home page (
home.jsp
)
First a login page is shown to the user, and if the correct username and password are provided, they log in and get redirected to the home page.
I've successfully managed to create my small webapp, writing down a custom login interceptor and everything's OK and working as expected. I'm able to redirect the user to the login page if he/she tries to call the HomeAction
( which results in home.jsp
if you previously logged in) directly like http://myserver/homeAction
.
Problem comes when I try to access JSPs directly like this:
http://myserver/home
As I'm using this Convention plugin
, Struts fetches my home.jsp
plugin and displays it. This is not the behaviour I expected, as home.jsp
should be shown only as a loginAction
successful result.
Things I tried to solve this issue
Well, as far as I googled, putting my JSPs inside /WEB-INF/
directory should prevent them to be accessed, but it doesn't, as all my JSPs are in /WEB-INF/content/
.
Another thing I tried was blocking access to any JSP
resource (blocking *.JSP
requests). This does the trick as long as you try to access myserver/home.jsp
, but fails (as expected) when accessing myserver/home
.
EDIT: There's another question in stackoverflow about this issue but I can't understand the answer:
Struts 2 Convention Plugin and JSP files under WEB-INF
INFORMATION UPDATE: I've found that Struts2 convention plugin uses something called "actionless results" so you can access your JSPs
inside your WEB-INF/content
directory by invoking the JSP
without it's extension and it will deal with it as a dummy action which returns that JSP
on success. This is an example to illustrate what I'm trying to explain:
If I have home.jsp
in my WEB-INF/content
directory and call http://myserver/home
, Struts2 will "trigger" an action whose result is going to be home.jsp
. The solution for the problem then is going to be disabling this "actionless" results.
I'll keep updating the question as I head towards the solution if nobody provides an answer.
See Question&Answers more detail:
os