Is it a good idea to place JSP pages in the WEB-INF folder in Apache Struts?

I am trying to implement my project in Apache Struts 2, but I am not very familiar with this technology. Meanwhile, I saw somewhere that this is an effective method for creating Java web page pages (JSPs) in the WEB-INF folder. At the forum, they say that this will increase the security of the website, because the JSP page cannot be accessed directly through the URL, but only through its action.

I created several pages, but the problem is that I have to write in all my actions, such as:

<action name=".." class=".." method=".." > <result name="success"> /WEB-INF/pages/index.jsp</result> </action> 

I got the right results by writing it like this: but is this a good way to write action pages like this ?. Will this cause any problems in my project? Is it possible to remove this / WEB-INF / in action using a namespace?

+4
source share
2 answers

It looks like you're looking to reduce your configuration (at least in part). See "Struts2-conventions-plugin": http://struts.apache.org/2.2.3.1/docs/convention-plugin.html

By default, he likes the pages to be placed (it's easy to override, but I'm not worried): / WEB -INF / content / my-page.jsp

This saves a lot on xml setup. I almost do not use xml, except to set the global struts2 parameters (development mode and set the theme to simple). In addition, annotations take care of the rest. You must try.

The conventions plugin does not stop you from using xml, where it is convenient for you, since xml takes precedence and does not cause any problems when using fragments.

+4
source

/WEB-INF required because this is part of the JSP path. The package / action namespace has nothing to do with JSP path resolution (in the package by default, without plugins).

It also has nothing to do with Tiles; Tiles use their own configuration file, and full paths to the JSP location are also required. In the Struts 2 configuration, you will reference fragment definitions (and use the result type "tiles" ).

+2
source

Source: https://habr.com/ru/post/1385003/


All Articles