tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From BARRAUD Valérie <vBARR...@aston.fr>
Subject RE: usebean
Date Thu, 31 May 2001 10:05:39 GMT

Usually, one uses request.setAttribute() to link a JavaBean (data) and a JSP
page (data displayer) :
- MyServlet.java :
	MyJavaBean myJavaBean = new MyJavaBean(...);
	request.setAttribute("mrBean", myJavaBean); // link JavaBean/JSP
            RequestDispatcher req =
getServletContext().getRequestDispatcher("MyPage.jsp");
            req.forward(request,response);
- MyPage.jsp :
	<jsp:useBean id="mrBean" class="mypackage.MyJavaBean"
scope="request" />
	...
		<form id="frm" name="frm" action="<%=
response.encodeURL("/servlet/mypackage.MyServlet") %>" method="post">
		...
To use a constante, try the JSP syntax expression:
<%=Constants.ATTR_MY_HANDLER %> after importing the file : I didn't test it
!



> -----Message d'origine-----
> De:	Egidijus Drobavicius [SMTP:egidijus@vb.lt]
> Date:	jeudi 31 mai 2001 10:43
> À:	tomcat-user@jakarta.apache.org
> Objet:	jsp:usebean
> 
> Hi,
> I've got one question:
> I'd like to keep the constant string values in the single place to avoid
> the
> mess. So I have class Constants.
> let's say Constants have atrribute ATTR_MY_HANDLER="myHandler"
> I use then code like this session.getAttribute(Constants.ATTR_MY_HANDLER).
> This is OK
> In jsp side i'd like to store this bean to session using jsp:usebean
> directive.
> But as i see the parser gets confused at this point if i write smth like
> this
> <jsp:useBean id=Constants.ATTR_MY_HANDLER scope="session"
> class="MyHandler"
> />
> It insists that id value is of type String and is placed between "".
> Is it possible to work around in nice way this situation or do I have to
> place this attribute to the session manualy? I do hate using same
> attribute
> in several places as it definetly leads to mistakes (i.e. I will not use
> <jsp:useBean id="myHandler" scope="session" class="MyHandler" />
> 
> Regards,
> 
> Egidijus Drobavicius
> AB Vilniaus Bankas
> http://www.vb.lt
> tel. + 370 2 682706

Mime
View raw message