param & paramValues
1. We can use these implicit objects to retrieve request parameter values. These implicit objects works just like getParameter() and getParameterNames() in servlet.
Expression Language code | Jsp code |
param paramValues | request. getParameter (String name ); request. getParameterValues ( ); |
Ex: 1 ${param.x}
It prints the value associates with request parameter x .
If the parameter is associated with multiple values, then it prints the first value.
If the specified parameter is not available then we will get blank space.
Ex:2 $ {paramValues.x[0] }
It prints first value.
$ {paramValues. x[1]}
It prints second value.
login.jsp
<body > <form action = "/Scwcd_jsp/test.jsp"> Enter name: <input type = 'text' name = "name"> <br> Enter mail : <input type = 'text' name = "mail"> <br> Enter Food1: <input type = 'text' name = "food"><br> Enter Food2: <input type = text name = "food"><br> <input type = "submit"> </form> </body> |
test.jsp
<%@ page isELIgnored="false" %> <table border = 2> <tr><td>param.name :</td><td>${param.name}</td></tr> <tr><td>param.age:</td><td>${param.age}</td></tr> <tr><td>param.food:</td><td>${param.food}</td></tr> <tr><td>paramVales.name[0]:</td><td>${paramVales.name[0]}</td></tr> <tr><td>paramValues.food[0]:</td><td>${paramValues.food[0]}</td></tr> <tr><td>paramValues.food[100]:</td><td>${paramValues.food[100]}</td></tr> <tr><td>paramValues.food[1]:</td><td>${paramValues.food[1]}</td></tr> </table> |
Case 1: http://localhost:8080/Scwcd_jsp/login.jsp
Case 2: Enter name, mail id,food1 and food2 and click on submitNote: Expression Language handles NullPointerException and ArrayIndexOutOfBoundsException very nicely it just suppresses them and prints blank space.
No comments:
Post a Comment