You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by vijay vijay <vi...@gmail.com> on 2007/11/16 09:40:14 UTC

how can i get my servlet result to jsp page

Hi
       i am writting a database connectionin action, here i wanted to put
tth result back in to a jsp page.
in jsp what i need to write

any one help me here

Re: how can i get my servlet result to jsp page

Posted by vijay vijay <vi...@gmail.com>.
i am using strut2 only thats why i asked you i am not able proceed further

On 11/16/07, Thilo Ettelt <te...@carmunity.de> wrote:
>
> I forgot to ask are you using Struts 1 or 2?
>
> In any case you should define your action mappings in the struts.xml.
> There you will define the different jsp results for your action. I don't
> think you need the requestdispatcher for that?
>
>
> - Thilo
>
> vijay vijay wrote:
> > Hi i am having small requirement like i have to connect to db from db i
> have
> > select ted the emp table from there i need to show that result in my
> > jsp.ihave written java code like this below in action .here i am not
> > able to knw
> > how to proceed from here
> >
> > can u help me here
> >
> > *
> >
> > public* *class* DbConnect {
> >
> > String result=*null*,SUCCESS;
> >
> > *public* String execute()
> >
> > {
> >
> > *try*{
> >
> > Connection con;
> >
> > Class.*forName*("oracle.jdbc.driver.OracleDriver").newInstance();
> >
> > con=DriverManager.*getConnection*("jdbc:oracle:thin:@192.168.0.186
> > :1521:earchive","scott","tiger");
> >
> > Statement stmt=con.createStatement();
> >
> > ResultSet rs = stmt.executeQuery("select * from emp");
> >
> > *if*(rs.next())
> >
> > {
> >
> > System.*out*.println(rs.getString(1));
> >
> > System.*out*.println(rs.getString(2));
> >
> > System.*out*.println(rs.getString(3));
> >
> > System.*out*.println(rs.getString(4));
> >
> > result=SUCCESS;
> >
> > *return* result;
> >
> > }
> >
> > // RequestDispatcher
> > requestDispatcher=getServletContext().getRequestDispatcher("/test.jsp");
> >
> > //requestDispatcher.forward(request,response);
> >
> >  }
> >
> > *catch*(Exception e){
> >
> > e.printStackTrace();
> >
> > }
> >
> > *return* result;
> >
> >
> >
> > On 11/16/07, Thilo Ettelt <te...@carmunity.de> wrote:
> >
> >> sure, in your action method you can define:
> >>
> >> ValueStack stack = ActionContext.getContext().getValueStack();
> >>
> >> and then fill whatever object you have into the valuestack:
> >>
> >> String sample = "Hello World";
> >> stack.set("myIdentifier", sample);
> >>
> >> In your JSP you can use the s:property tag to display your String in
> >> this case:
> >>
> >> <s:property value="myIdentifier"/>
> >>
> >> you can put any ognl expression into the value part, read the docs for
> >> more info on ognl.
> >> for example you could have put an array onto the stack and call the
> >> object at index 5 by using:
> >>
> >> <s:property value="myIdentifierArray[5]"/>
> >>
> >> You can also call methods like this method of a String object:
> >>
> >> <s:property value="myIdentifier.toLowerCase"/>
> >>
> >>
> >> - Thilo
> >>
> >> vijay vijay wrote:
> >>
> >>> Hi can u give me some sample code to me
> >>>
> >>> On 11/16/07, Thilo Ettelt <te...@carmunity.de> wrote:
> >>>
> >>>
> >>>> Access the ValueStack in your action, it allows you to store objects
> >>>>
> >> and
> >>
> >>>> you can retrieve them from your jsp. You might need to know about the
> >>>> ActionContext object accessable from your action.
> >>>>
> >>>> Read more from the docs :)
> >>>>
> >>>>
> >>>> - Thilo
> >>>>
> >>>> vijay vijay wrote:
> >>>>
> >>>>
> >>>>> Hi
> >>>>>        i am writting a database connectionin action, here i wanted
> to
> >>>>>
> >>>>>
> >>>> put
> >>>>
> >>>>
> >>>>> tth result back in to a jsp page.
> >>>>> in jsp what i need to write
> >>>>>
> >>>>> any one help me here
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>> ---------------------------------------------------------------------
> >>>> 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: how can i get my servlet result to jsp page

Posted by Thilo Ettelt <te...@carmunity.de>.
I forgot to ask are you using Struts 1 or 2?

In any case you should define your action mappings in the struts.xml.
There you will define the different jsp results for your action. I don't 
think you need the requestdispatcher for that?


- Thilo

vijay vijay wrote:
> Hi i am having small requirement like i have to connect to db from db i have
> select ted the emp table from there i need to show that result in my
> jsp.ihave written java code like this below in action .here i am not
> able to knw
> how to proceed from here
>
> can u help me here
>
> *
>
> public* *class* DbConnect {
>
> String result=*null*,SUCCESS;
>
> *public* String execute()
>
> {
>
> *try*{
>
> Connection con;
>
> Class.*forName*("oracle.jdbc.driver.OracleDriver").newInstance();
>
> con=DriverManager.*getConnection*("jdbc:oracle:thin:@192.168.0.186
> :1521:earchive","scott","tiger");
>
> Statement stmt=con.createStatement();
>
> ResultSet rs = stmt.executeQuery("select * from emp");
>
> *if*(rs.next())
>
> {
>
> System.*out*.println(rs.getString(1));
>
> System.*out*.println(rs.getString(2));
>
> System.*out*.println(rs.getString(3));
>
> System.*out*.println(rs.getString(4));
>
> result=SUCCESS;
>
> *return* result;
>
> }
>
> // RequestDispatcher
> requestDispatcher=getServletContext().getRequestDispatcher("/test.jsp");
>
> //requestDispatcher.forward(request,response);
>
>  }
>
> *catch*(Exception e){
>
> e.printStackTrace();
>
> }
>
> *return* result;
>
>
>
> On 11/16/07, Thilo Ettelt <te...@carmunity.de> wrote:
>   
>> sure, in your action method you can define:
>>
>> ValueStack stack = ActionContext.getContext().getValueStack();
>>
>> and then fill whatever object you have into the valuestack:
>>
>> String sample = "Hello World";
>> stack.set("myIdentifier", sample);
>>
>> In your JSP you can use the s:property tag to display your String in
>> this case:
>>
>> <s:property value="myIdentifier"/>
>>
>> you can put any ognl expression into the value part, read the docs for
>> more info on ognl.
>> for example you could have put an array onto the stack and call the
>> object at index 5 by using:
>>
>> <s:property value="myIdentifierArray[5]"/>
>>
>> You can also call methods like this method of a String object:
>>
>> <s:property value="myIdentifier.toLowerCase"/>
>>
>>
>> - Thilo
>>
>> vijay vijay wrote:
>>     
>>> Hi can u give me some sample code to me
>>>
>>> On 11/16/07, Thilo Ettelt <te...@carmunity.de> wrote:
>>>
>>>       
>>>> Access the ValueStack in your action, it allows you to store objects
>>>>         
>> and
>>     
>>>> you can retrieve them from your jsp. You might need to know about the
>>>> ActionContext object accessable from your action.
>>>>
>>>> Read more from the docs :)
>>>>
>>>>
>>>> - Thilo
>>>>
>>>> vijay vijay wrote:
>>>>
>>>>         
>>>>> Hi
>>>>>        i am writting a database connectionin action, here i wanted to
>>>>>
>>>>>           
>>>> put
>>>>
>>>>         
>>>>> tth result back in to a jsp page.
>>>>> in jsp what i need to write
>>>>>
>>>>> any one help me here
>>>>>
>>>>>
>>>>>
>>>>>           
>>>> ---------------------------------------------------------------------
>>>> 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: how can i get my servlet result to jsp page

Posted by vijay vijay <vi...@gmail.com>.
Hi i am having small requirement like i have to connect to db from db i have
select ted the emp table from there i need to show that result in my
jsp.ihave written java code like this below in action .here i am not
able to knw
how to proceed from here

can u help me here

*

public* *class* DbConnect {

String result=*null*,SUCCESS;

*public* String execute()

{

*try*{

Connection con;

Class.*forName*("oracle.jdbc.driver.OracleDriver").newInstance();

con=DriverManager.*getConnection*("jdbc:oracle:thin:@192.168.0.186
:1521:earchive","scott","tiger");

Statement stmt=con.createStatement();

ResultSet rs = stmt.executeQuery("select * from emp");

*if*(rs.next())

{

System.*out*.println(rs.getString(1));

System.*out*.println(rs.getString(2));

System.*out*.println(rs.getString(3));

System.*out*.println(rs.getString(4));

result=SUCCESS;

*return* result;

}

// RequestDispatcher
requestDispatcher=getServletContext().getRequestDispatcher("/test.jsp");

//requestDispatcher.forward(request,response);

 }

*catch*(Exception e){

e.printStackTrace();

}

*return* result;



On 11/16/07, Thilo Ettelt <te...@carmunity.de> wrote:
>
> sure, in your action method you can define:
>
> ValueStack stack = ActionContext.getContext().getValueStack();
>
> and then fill whatever object you have into the valuestack:
>
> String sample = "Hello World";
> stack.set("myIdentifier", sample);
>
> In your JSP you can use the s:property tag to display your String in
> this case:
>
> <s:property value="myIdentifier"/>
>
> you can put any ognl expression into the value part, read the docs for
> more info on ognl.
> for example you could have put an array onto the stack and call the
> object at index 5 by using:
>
> <s:property value="myIdentifierArray[5]"/>
>
> You can also call methods like this method of a String object:
>
> <s:property value="myIdentifier.toLowerCase"/>
>
>
> - Thilo
>
> vijay vijay wrote:
> > Hi can u give me some sample code to me
> >
> > On 11/16/07, Thilo Ettelt <te...@carmunity.de> wrote:
> >
> >> Access the ValueStack in your action, it allows you to store objects
> and
> >> you can retrieve them from your jsp. You might need to know about the
> >> ActionContext object accessable from your action.
> >>
> >> Read more from the docs :)
> >>
> >>
> >> - Thilo
> >>
> >> vijay vijay wrote:
> >>
> >>> Hi
> >>>        i am writting a database connectionin action, here i wanted to
> >>>
> >> put
> >>
> >>> tth result back in to a jsp page.
> >>> in jsp what i need to write
> >>>
> >>> any one help me here
> >>>
> >>>
> >>>
> >> ---------------------------------------------------------------------
> >> 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: how can i get my servlet result to jsp page

Posted by Dave Newton <ne...@yahoo.com>.
Why wouldn't you just expose an action property
through normal means?

--- Thilo Ettelt <te...@carmunity.de> wrote:

> sure, in your action method you can define:
> 
> ValueStack stack =
> ActionContext.getContext().getValueStack();
> 
> and then fill whatever object you have into the
> valuestack:
> 
> String sample = "Hello World";
> stack.set("myIdentifier", sample);
> 
> In your JSP you can use the s:property tag to
> display your String in 
> this case:
> 
> <s:property value="myIdentifier"/>
> 
> you can put any ognl expression into the value part,
> read the docs for 
> more info on ognl.
> for example you could have put an array onto the
> stack and call the 
> object at index 5 by using:
> 
> <s:property value="myIdentifierArray[5]"/>
> 
> You can also call methods like this method of a
> String object:
> 
> <s:property value="myIdentifier.toLowerCase"/>
> 
> 
> - Thilo
> 
> vijay vijay wrote:
> > Hi can u give me some sample code to me
> >
> > On 11/16/07, Thilo Ettelt <te...@carmunity.de> wrote:
> >   
> >> Access the ValueStack in your action, it allows
> you to store objects and
> >> you can retrieve them from your jsp. You might
> need to know about the
> >> ActionContext object accessable from your action.
> >>
> >> Read more from the docs :)
> >>
> >>
> >> - Thilo
> >>
> >> vijay vijay wrote:
> >>     
> >>> Hi
> >>>        i am writting a database connectionin
> action, here i wanted to
> >>>       
> >> put
> >>     
> >>> tth result back in to a jsp page.
> >>> in jsp what i need to write
> >>>
> >>> any one help me here
> >>>
> >>>
> >>>       
> >>
>
---------------------------------------------------------------------
> >> 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: how can i get my servlet result to jsp page

Posted by Thilo Ettelt <te...@carmunity.de>.
sure, in your action method you can define:

ValueStack stack = ActionContext.getContext().getValueStack();

and then fill whatever object you have into the valuestack:

String sample = "Hello World";
stack.set("myIdentifier", sample);

In your JSP you can use the s:property tag to display your String in 
this case:

<s:property value="myIdentifier"/>

you can put any ognl expression into the value part, read the docs for 
more info on ognl.
for example you could have put an array onto the stack and call the 
object at index 5 by using:

<s:property value="myIdentifierArray[5]"/>

You can also call methods like this method of a String object:

<s:property value="myIdentifier.toLowerCase"/>


- Thilo

vijay vijay wrote:
> Hi can u give me some sample code to me
>
> On 11/16/07, Thilo Ettelt <te...@carmunity.de> wrote:
>   
>> Access the ValueStack in your action, it allows you to store objects and
>> you can retrieve them from your jsp. You might need to know about the
>> ActionContext object accessable from your action.
>>
>> Read more from the docs :)
>>
>>
>> - Thilo
>>
>> vijay vijay wrote:
>>     
>>> Hi
>>>        i am writting a database connectionin action, here i wanted to
>>>       
>> put
>>     
>>> tth result back in to a jsp page.
>>> in jsp what i need to write
>>>
>>> any one help me here
>>>
>>>
>>>       
>> ---------------------------------------------------------------------
>> 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: how can i get my servlet result to jsp page

Posted by vijay vijay <vi...@gmail.com>.
Hi can u give me some sample code to me

On 11/16/07, Thilo Ettelt <te...@carmunity.de> wrote:
>
> Access the ValueStack in your action, it allows you to store objects and
> you can retrieve them from your jsp. You might need to know about the
> ActionContext object accessable from your action.
>
> Read more from the docs :)
>
>
> - Thilo
>
> vijay vijay wrote:
> > Hi
> >        i am writting a database connectionin action, here i wanted to
> put
> > tth result back in to a jsp page.
> > in jsp what i need to write
> >
> > any one help me here
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: how can i get my servlet result to jsp page

Posted by Thilo Ettelt <te...@carmunity.de>.
Access the ValueStack in your action, it allows you to store objects and 
you can retrieve them from your jsp. You might need to know about the 
ActionContext object accessable from your action.

Read more from the docs :)


- Thilo

vijay vijay wrote:
> Hi
>        i am writting a database connectionin action, here i wanted to put
> tth result back in to a jsp page.
> in jsp what i need to write
>
> any one help me here
>
>   


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