I have a situation in which I think it is a good idea to use an EL function that is a void java method. This is a simple jsp to update a database of people’s first and last name. So, there are two text fields, name and password. The user enters them and clicks submit, and it forwards these with POST to another jsp. This jsp simply calls the EL function, let’s call it “put” that takes two parameters and is derived from a java method putPerson(String, String) that gets a connection to the database and puts the first and last name in their proper places. Now, putPerson is void because all it does is put the strings in the database. So, is this bad programming practice, and if so, why? It seems to me to be a quick and elegant solution, and it works. The only problem is that you can’t just call it by saying ${put(first, last)} because that prints out “<“, for some reason, but that’s easy enough to work around. So why do they recommend to not use EL functions with void return types?
I have a situation in which I think it is a good idea to
Share
Printing
<would be coming from somewhere else, or is a bug in the EL parser. But either way, you should not do that in an EL function.EL functions are meant to be utilities – for example
.substring(),.join()(arrays), etc. And they are used while you are displaying the page and need some more complex presentation logic.What you want to do is a typical story and it is done in a servlet (or any other action component, if you are using a framework).