You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by pck <pe...@gmail.com> on 2005/02/11 16:48:24 UTC

How to pass variable from servlet to jsp?

Hello,

I'm very begginer in java and struts so please forgive me for this question...

I've got servlet: 

    <action-mappings>
        <action path="/actions/register1" 
                type="RegisterAction1">
            <forward name="success" 
                     path="/WEB-INF/results/result1success.jsp"/>
            <forward name="filed - bad xml recived"
                     path="/WEB-INF/results/result1failedxmlbad.jsp"/>
            <forward name="SQL - insert problem"
                     path="/WEB-INF/results/result1sqlproblem.jsp"/>
        </action>
    </action-mappings>

When I visit with my IE/Firefox /actions/register1.do it is evoked.
In this servlet I do some caluculations and then i want to show this
on the screen.

For example my variable look like:
String temp_ = "test";

And then do: return(mapping.findForward("success"));

So result1success.jsp must display this temp_ on the screen.

How to do it?


TIA!
pck.

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


Re: How to pass variable from servlet to jsp?

Posted by Larry Meadors <la...@gmail.com>.
Use request.setAttribute(name, value) to put the data into request
scope, then from your jsp, use jstl to get to the value:

---
// in your action class:
request.setAttribute("foo", "My String");
---

---
<!-- in your jsp: -->
<c:out value="${foo}" />
---

Google for a JSTL tutorial - there are a pile of them.

Larry

On Fri, 11 Feb 2005 16:48:24 +0100, pck <pe...@gmail.com> wrote:
> Hello,
> 
> I'm very begginer in java and struts so please forgive me for this question...
> 
> I've got servlet:
> 
>     <action-mappings>
>         <action path="/actions/register1"
>                 type="RegisterAction1">
>             <forward name="success"
>                      path="/WEB-INF/results/result1success.jsp"/>
>             <forward name="filed - bad xml recived"
>                      path="/WEB-INF/results/result1failedxmlbad.jsp"/>
>             <forward name="SQL - insert problem"
>                      path="/WEB-INF/results/result1sqlproblem.jsp"/>
>         </action>
>     </action-mappings>
> 
> When I visit with my IE/Firefox /actions/register1.do it is evoked.
> In this servlet I do some caluculations and then i want to show this
> on the screen.
> 
> For example my variable look like:
> String temp_ = "test";
> 
> And then do: return(mapping.findForward("success"));
> 
> So result1success.jsp must display this temp_ on the screen.
> 
> How to do it?
> 
> TIA!
> pck.
> 
> ---------------------------------------------------------------------
> 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