jeudi 30 janvier 2020

How do JSP pages find the correct setters for parameters

Say I have the following JSP page:

<jsp:useBean id="bean" scope="page" class="com.test.jsp.beans.TestBean"/>
<jsp:setProperty name="bean" property="*"/>
...
<input type="text" name="test" value="test value"/>
...

and the bean:

package com.test.jsp.beans;

public class TestBean {
    public String test;

    public String getTest() {
        return test;
    }

    public void setTest(String test) {
        this.test = test;
    }
}

How does java know to pass the value from the <input> tag to the setTest() method?

I would like to understand the inner workings of how they are linked, I assume reflection is used.

Does java look for the setter method or does it look for the variable?

Does the setter name need to be set + <input> name?

Does the setter need to contain exactly one parameter?

Does that parameter need to be the same name as the <input> tag?

Does the setter even need parameters?

Does capitalization matter?

etc...





Aucun commentaire:

Enregistrer un commentaire