I am learning JSP and Servlet and I found something odd - If I use the following code:
request.setAttribute("m", m);
RequestDispatcher rd = request.getRequestDispatcher("welcome.jsp");
rd.forward(request, response);
where request
is an HttpServletRequest
object and m
is an object of the Model
class, I can access and display the values of the private variables of m
in my JSP page (welcome.jsp).
Relevant JSP code for welcome.jsp:
Hello, <strong>${m.name}</strong>! Your data has been validated and is displayed below:<br/>
<br/>
Number: <strong> ${m.number} </strong>
<br/>
<br/>
Birth Month: <strong> ${m.month} </strong>
Relevant Java code for the Model class:
public class Model {
private String name;
private String number;
private String[] hobby;
private int month;
// remaining code...