You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Josh Holtzman <jh...@americandatacompany.com> on 2004/04/17 17:54:26 UTC

Detrmining which module from within JSP

Hello,

 

Can anyone suggest a means to determine the current struts application
module from within a JSP?  

 

Would it be possible to use a Bean or Logic tag to make this determination?

 

Thanks again for any suggestions.

 

Regards,

 

Josh Holtzman

American Data Company

jholtzman@americandatacompany.com

Voice: (310) 470-1257

Fax:    (310) 362-8454

 

Sun Microsystems iForce Partner

 


Re: Buffering the ouput of a JSP page within an action

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
Struts has a <bean:include> tag - not used it myself, but the docs say it
performs an internal dispatch to a component or URL and stores the response
in a bean. Maybe you could use that as part of a solution.

http://jakarta.apache.org/struts/userGuide/struts-bean.html#include


I have a simple tag (StoreTag) which does something similar, except you
embed the jsp stuff you want in the tag. So you could set up a jsp with this
tag and then in your action use the RequestDispatcher to include the jsp and
put the output into a bean. Something like:


 ------SamplePage.jsp-----
 <custom:store name="myForm" property="samplePage" scope="session">
     ------ format your jsp stuff here -----
 </custom:store>


-------in your Action.execute()-------
// Get formatted email content
RequestDispatcher rd =
servlet.getServletContext().getRequestDispatcher("myJspPage.jsp");
rd.include(request, response);
String samplePage= form.getSamplePage();

In this example, you would need so set up the "samplePage" as a property in
your ActionForm.

----------StoreTag Source-----------------
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.JspException;
import org.apache.struts.util.RequestUtils;
import org.apache.commons.beanutils.BeanUtils;

public class StoreTag extends BodyTagSupport {

protected String name = null;
protected String property = null;
protected String scope = null;

public StoreTag() {
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setProperty(String property) {
this.property = property;
}
public String getProperty() {
return property;
}
public void setScope(String scope) {
this.scope = scope;
}
public String getScope() {
return scope;
}
public int doAfterBody() throws JspException {
String value = null;
if (bodyContent != null) {
value = bodyContent.getString().trim();
}
if (property == null) {
pageContext.setAttribute(name, value, RequestUtils.getScope(scope));
} else {
// find the bean
Object bean = RequestUtils.lookup(pageContext, name, scope);
if (bean == null)
throw new JspException("Cannot find bean '"+name+"' in scope '"+scope+"'");
try {
BeanUtils.setProperty(bean, property, value);
}
catch (Exception ex) {
throw new JspException("Error setting property '"+property+"' on bean
'"+name+"' in scope '"+scope+"': "+ex);
}
}
return (SKIP_BODY);
}
public void release() {
name = null;
property = null;
scope = null;
}
}

----- Original Message ----- 
From: "Amine Bousta" <am...@freesurf.fr>
Sent: Monday, April 19, 2004 11:00 AM


> Hello,
>
> I'm trying to write a struts action that could save in a database and
> send by e-mail the output of a JSP page.
> This JSP page needs attributes values that are stored in the session
> context. In other words, I need ServletContext of the struts action and
> the JSP page to be the same.
>
> I first tried to use the Java "URL" object to perform this action but it
> creates a separate ServletContext.
>
> I didn't find any solution to this issue on the internet.
> Does anybody can help me?...
>
> Amine



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE : Buffering the ouput of a JSP page within an action

Posted by Amine Bousta <ab...@lxsolutions.com>.
Thank you very much.
It seems that Velocity is a good solution for my pb.
I just have now to replace variables of the template by object values
stored in my session within my struts action (because I have to save the
result text in the database as well)

Thank you again for this link

Amine

-----Message d'origine-----
De : Wiebe de Jong [mailto:wiebedj@shaw.ca] 
Envoyé : lundi 19 avril 2004 20:51
À : 'Struts Users Mailing List'
Objet : RE: Buffering the ouput of a JSP page within an action

Check out Matt Raible's solution to templated-email using Velocity. It
is
good and I intend to use it for this purpose.

http://www.theserverside.com/blogs/showblog.tss?id=SpringVelocityEmail

Wiebe

-----Original Message-----
From: Amine Bousta [mailto:amine.bousta@freesurf.fr] 
Sent: Monday, April 19, 2004 3:01 AM
To: 'Struts Users Mailing List'
Subject: Buffering the ouput of a JSP page within an action

Hello,

I'm trying to write a struts action that could save in a database and
send by e-mail the output of a JSP page.
This JSP page needs attributes values that are stored in the session
context. In other words, I need ServletContext of the struts action and
the JSP page to be the same.
 
I first tried to use the Java "URL" object to perform this action but it
creates a separate ServletContext.

I didn't find any solution to this issue on the internet.
Does anybody can help me?...

Amine



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Buffering the ouput of a JSP page within an action

Posted by Wiebe de Jong <wi...@shaw.ca>.
Check out Matt Raible's solution to templated-email using Velocity. It is
good and I intend to use it for this purpose.

http://www.theserverside.com/blogs/showblog.tss?id=SpringVelocityEmail

Wiebe

-----Original Message-----
From: Amine Bousta [mailto:amine.bousta@freesurf.fr] 
Sent: Monday, April 19, 2004 3:01 AM
To: 'Struts Users Mailing List'
Subject: Buffering the ouput of a JSP page within an action

Hello,

I'm trying to write a struts action that could save in a database and
send by e-mail the output of a JSP page.
This JSP page needs attributes values that are stored in the session
context. In other words, I need ServletContext of the struts action and
the JSP page to be the same.
 
I first tried to use the Java "URL" object to perform this action but it
creates a separate ServletContext.

I didn't find any solution to this issue on the internet.
Does anybody can help me?...

Amine



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Buffering the ouput of a JSP page within an action

Posted by Amine Bousta <am...@freesurf.fr>.
Hello,

I'm trying to write a struts action that could save in a database and
send by e-mail the output of a JSP page.
This JSP page needs attributes values that are stored in the session
context. In other words, I need ServletContext of the struts action and
the JSP page to be the same.
 
I first tried to use the Java "URL" object to perform this action but it
creates a separate ServletContext.

I didn't find any solution to this issue on the internet.
Does anybody can help me?...

Amine



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


OT: session of previously logined users is retrieved

Posted by Ramil Mirhasanov <ra...@dolunay.com.tr>.
Hi,

I encountered a problem while testing my web application in the internet.
When user is authorized, the parameters of this user are stored in the
"UserInfo" object and put to the session, as the below:

                    /** LoginAction.java**/

  if (errorDetected == false){
           UserInfo userInfoBean = userDBBean.ParseUserInfo(username,
verify);
           userInfoBean.setU_KulAdiNosu(verify);
           HttpSession session = req.getSession();
           session.setAttribute("user", userInfoBean );
           logined = "true";
           session.setAttribute("logined", logined );
...
During the tests, when you login to the application, surprisibgly the
session of previously logined user is retrieved.

The UserInfo object is retreived later in jsp page :
UserInfo userInfoBean = ( UserInfo )session.getAttribute("user");

Thank you in advance, for your help!
Ramil.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Detrmining which module from within JSP

Posted by "Kunal H. Parikh" <ku...@carsales.com.au>.
Hey All!

Just for the record,
<c:out value="${requestScope['org.apache.struts.action.Module'].prefix}"/>
(Incorrect)
	
^^^^^^
<c:out value="${requestScope['org.apache.struts.action.MODULE].prefix}"/>


Along a similar note, how would one work out the name of the tile definition
being processed ? Any ideas ?


TIA,

Kunal

-----Original Message-----
From: Craig McClanahan [mailto:craigmcc@apache.org] 
Sent: Monday, 19 April 2004 16:03
To: Struts Users Mailing List
Subject: Re: Detrmining which module from within JSP

Kunal H. Parikh wrote:

>Hi All!
>
>Craig's suggestion works great!
>
>However, it appears to me that dot delimited request variable names don't
>work with the JSTL.
>
>Eg:
><c:out value="${org.apache.struts.action.MODULE}" />
><c:out value="${requestScope.org.apache.struts.action.MODULE}" />
>
>The above prints nothing and therefore a .prefix also fails.
>
>Does anyone know if this is a JSTL bug, or is there something that needs to
>change in struts?
>
>Or is there something I am doing incorrectly?
>
>  
>
This isn't a bug, it's a feature :-).  Actually, this happens because 
the "." character is an operator in the EL syntax, so it can't be used 
literally in an expression.  Try something like this:

  The prefix is <c:out 
value="${requestScope['org.apache.struts.action.Module'].prefix}"/>

instead.  This works because the "." operator and the "[...]" bracket 
syntax are treated identically in the EL syntax, just as they are in 
JavaScript.  Therefore, you have to enclose the string constant that 
includes periods in quotes to make things work as you expect.

>TIA,
>
>Kunal
>
>  
>
Craig


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Detrmining which module from within JSP

Posted by Craig McClanahan <cr...@apache.org>.
Kunal H. Parikh wrote:

>Hi All!
>
>Craig's suggestion works great!
>
>However, it appears to me that dot delimited request variable names don't
>work with the JSTL.
>
>Eg:
><c:out value="${org.apache.struts.action.MODULE}" />
><c:out value="${requestScope.org.apache.struts.action.MODULE}" />
>
>The above prints nothing and therefore a .prefix also fails.
>
>Does anyone know if this is a JSTL bug, or is there something that needs to
>change in struts?
>
>Or is there something I am doing incorrectly?
>
>  
>
This isn't a bug, it's a feature :-).  Actually, this happens because 
the "." character is an operator in the EL syntax, so it can't be used 
literally in an expression.  Try something like this:

  The prefix is <c:out 
value="${requestScope['org.apache.struts.action.Module'].prefix}"/>

instead.  This works because the "." operator and the "[...]" bracket 
syntax are treated identically in the EL syntax, just as they are in 
JavaScript.  Therefore, you have to enclose the string constant that 
includes periods in quotes to make things work as you expect.

>TIA,
>
>Kunal
>
>  
>
Craig


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Detrmining which module from within JSP

Posted by "Kunal H. Parikh" <ku...@carsales.com.au>.
Hi All!

Craig's suggestion works great!

However, it appears to me that dot delimited request variable names don't
work with the JSTL.

Eg:
<c:out value="${org.apache.struts.action.MODULE}" />
<c:out value="${requestScope.org.apache.struts.action.MODULE}" />

The above prints nothing and therefore a .prefix also fails.

Does anyone know if this is a JSTL bug, or is there something that needs to
change in struts?

Or is there something I am doing incorrectly?


TIA,

Kunal

-----Original Message-----
From: Craig McClanahan [mailto:craigmcc@apache.org] 
Sent: Sunday, 18 April 2004 10:17
To: Struts Users Mailing List
Subject: Re: Detrmining which module from within JSP

Josh Holtzman wrote:

>Hello,
>
> 
>
>Can anyone suggest a means to determine the current struts application
>module from within a JSP?
>
As long as you have correctly gone through an action first, the 
ModuleConfig object for the selected
module has been stored as a request attribute under the key 
"org.apache.struts.action.MODULE" (from Java code, you would use 
Globals.MODULE_KEY to reference this string).  So, you could say 
something like this in a JSP page:

  The current module prefix is
  <bean:write name="org.apache.struts.action.MODULE" property="prefix"/>

The Javadocs for org.apache.struts.Globals describe many other attribute 
names that Struts uses to store interesting things while processing a 
request.

>  
>
> 
>
>Would it be possible to use a Bean or Logic tag to make this determination?
>
> 
>
>Thanks again for any suggestions.
>
> 
>
>Regards,
>
> 
>
>Josh Holtzman
>
>  
>
Craig


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Detrmining which module from within JSP

Posted by Craig McClanahan <cr...@apache.org>.
Josh Holtzman wrote:

>Hello,
>
> 
>
>Can anyone suggest a means to determine the current struts application
>module from within a JSP?
>
As long as you have correctly gone through an action first, the 
ModuleConfig object for the selected
module has been stored as a request attribute under the key 
"org.apache.struts.action.MODULE" (from Java code, you would use 
Globals.MODULE_KEY to reference this string).  So, you could say 
something like this in a JSP page:

  The current module prefix is
  <bean:write name="org.apache.struts.action.MODULE" property="prefix"/>

The Javadocs for org.apache.struts.Globals describe many other attribute 
names that Struts uses to store interesting things while processing a 
request.

>  
>
> 
>
>Would it be possible to use a Bean or Logic tag to make this determination?
>
> 
>
>Thanks again for any suggestions.
>
> 
>
>Regards,
>
> 
>
>Josh Holtzman
>
>  
>
Craig


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org