With the introduction of Expression Language in JSP 2.0 it is recommended to use the EL instead of using a scripting elements / scriptlets. That means if we want to access a server-side objects it is recommended to use EL then to write some Java codes in the JSP pages.
For this purpose in JSP 2.0 we are given a feature to disable the scripting elements by defining a
scripting-invalid element within the
<jsp-property-group> in the deployment descriptor /
Here is the JSP configuration that you need to add in the web.xml file:
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>JSP Examples</display-name> <jsp-config> <jsp-property-group> <url-pattern>*.jsp</url-pattern> <scripting-invalid>true</scripting-invalid> </jsp-property-group> </jsp-config> </web-app>
When you try to request a JSP page that have a scripting elements in, it will give you an error message like this:
HTTP Status 500 - /sessionWriteRead.jsp (line: 10, column: 2) Scripting elements ( <%!, <jsp:declaration, <%=, <jsp:expression, <%, <jsp:scriptlet ) are disallowed here.
Latest posts by Wayan Saryada (see all)
- How do I do multipart upload using HttpClient? - January 11, 2017
- How do I convert number into Roman Numerals? - January 8, 2017
- How do I send POST request with a JSON body using the HttpClient? - January 7, 2017