Reputation: 2279
I'm trying implement my project in Apache Struts 2 but I'm not very familiar with the technology. Meanwhile, I had seen somewhere that it is an efficient method to create Java Server Pages (JSP) pages inside WEB-INF folder. In the forum they are saying that doing so will increase the security of the website because the JSP page cannot be accessed directly through URL but only through its action.
I have built some pages likewise but the problem is I have to write in all my actions like this :
<action name=".." class=".." method=".." >
<result name="success"> /WEB-INF/pages/index.jsp</result>
</action>
I got correct results writing it like this; but is it a good method to write the action pages like this?. Will this cause any problem in my project? Can I remove this /WEB-INF/ in the action by using namespace?
Upvotes: 4
Views: 5250
Reputation: 10458
What it sounds like you are looking for is to reduce your configuration (at least in part). Please see "struts2-conventions-plugin": http://struts.apache.org/2.2.3.1/docs/convention-plugin.html
By default it likes pages to be placed in (this is easy to override but I don't bother): /WEB-INF/content/my-page.jsp
It does save a great deal on configuring xml. I hardly use xml at all except to set global struts2 parameters (development mode and set the theme to simple). Other than that annotations take care of the rest. You should give it a try.
The conventions plugin does not prevent you from using xml where you are comfortable, as the xml takes precedence and it does not cause any issues in using tiles.
Upvotes: 4
Reputation: 160191
The /WEB-INF
is required, because it's part of the path to the JSP. The package/action namespace has nothing to do with JSP path resolution (in the default package, with no plugins, anyway).
This also has nothing to do with Tiles; Tiles uses its own configuration file, and also requires full pathnames to the JSP location. In the Struts 2 config you will refer to tile definitions (and use a "tiles"
result type).
Upvotes: 2