servlets - Initialize class with constructor in <jsp:useBean> -


i trying initialize class passing parameter constructor. need scope "page". know have 1 argument in constructor, how have 1 accepts parameter using <jsp:usebean>, , can called jsp page?

 public class extends b {     a(servletrequest req) {        super(req); } 

if there no-arg constructor, can use < jsp:usebean id="someid" class="mypackage.a" scope="page" /> tag. in usebean jsp tag, can't invoke constructor.

is there way initialize class constructor?

no.

either use <jsp:setproperty>,

<jsp:usebean id="someid" class="mypackage.a" scope="page">     <jsp:setproperty name="someid" property="request" value="${pagecontext.request}" /> </jsp:usebean> 

or use normal servlet:

request.setattribute("someid", new a(request)); 

it's way surprising tagged [servlets] on question while that's not used <jsp:usebean> 2 approaches of managing beans conflicting (one mvc level 1 , other mvc level 2). detail, see our servlets wiki page.

nonetheless, having bean property of httpservletrequest type fishy. there undoubtedly better ways achieve the concrete functional requirement incorrectly thought right solution.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -