Use struts2 value in JSP

Source: Internet
Author: User

The struts2 value is stored in valuestack. Suppose there is a string 'str', which is generally the value:

<S: property value = "str"/> or $ {STR}

If you want to use it in JSP, you can use the following:

<%@ PageImport="Com. opensymphony. xwork2.util. valuestack" %>

......

<% =(Valuestack) request. getattribute ("Struts. valuestack"). Findstring ("Str")%>

 

You can also put the value in valuestack into attribute first, and then directly take the value of attribute:

 
<S: Set Name="Str"Value="% {STR}" />

<% =Request. getattribute ("Str")%>

Call a function on the struts2 page

Method 1:

<S: Set Name = "str" value = "'Hello world'"> </S: Set>

<S: property value = "% {@ com. Common. Constant @ func (# Str)}"/>

 

Func is a static method in COM. Common. Constant.

STR is a dynamic parameter

 

Method 2:

<S: bean name = "com. Common. strutshelper" id = "helper"/>

<S: Set Name = "str" value = "'Hello world'"> </S: Set>

<S: property value = "# helper. func (# Str)"/>

Func is a common method in COM. Common. strutshelper.

STR is a dynamic method

S: bean is actually an instantiation of the strutshelper class, which is somewhat different from method 1. The function in method 1 must be static.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.