Go + summarize!! about how JSP pages are valued

Source: Internet
Author: User

1. Reception back to the table, by submitting a form, in the background there are set,get methods, can be directly taken. If you get through Request.getparameter (paramname), the null pointer exception is reported. Where request is an instance of HttpServletRequest. The workaround is to define the Get/set method of the request in the background action class. Where the Get method writes:

Public HttpServletRequest Getrequest () {

if (request = = null)

Request =servletactioncontext.getrequest ();

return request;

}

At this point, through Getrequest (). GetParameter (ParamName), it is possible to successfully obtain the request parameter value sent by the foreground.

By the way, not every form field in the foreground submission form generates a request parameter, but a form field with the Name property generates the request parameter. If more than one form field has the same name property, multiple form fields can generate only one request parameter, except that the parameter has multiple values. If a form field is set to disabled= "disabled", the form field no longer generates request parameters.

2. for a form, the attribute has the name of the form field, as long as the Get/set method of the member variable is the same as the value of the Name property in the background . The value of the form field is automatically obtained. For example <input name= "Ask" type= "text" value= ""/> a member variable ask is defined in the background action, with Setask () and Getask () method, <inputname= "Ask The value of "type=" text "/>" can be obtained dynamically from background settings.

3. The second method of getting the value:el expression: ${param}. Regardless of the value from the background, or the value of other front-end pages, can be obtained through ${}. The property values passed in the background (that is, properties set by the SetAttribute () method in the background) can also be obtained by means of an El expression. Incidentally, please. The property values set by Request.setattribute () in the front-end page are not available in the background, and the jump page (the principle is not ripe, but the feeling should not, but try to be the case).

4. Get through the struts2 tag:<s:property value= ""/>. One thing to note here: Value property, when to add "#", when do not add?

Answer: If you take the value in valuestack , you do not need to take #, you can take it directly. For example, the property value of an action instance is stored in valuestack , so the attribute in the action is not required with the # number. Note that when using the <s:iteratorid= "it" value= "Attrname" >, after using it to fetch object properties, it is necessary to add the # number . Take the value inside the Stack Context and you need to add #.

There may be readers who do not know what Valuestack and stack context store separately.

Here to help you put out the answers that others have given online: (common)

valuestack: Action all member variables, fielderrors,actionerrors,actionmessage,exception and your own custom interceptors or variables written in action

Eapricejsonstr is an attribute in action (with Set/get method)

<div >1---${eapricejsonstr}---</div>
<div >2---${action.eapricejsonstr}---</div>
<div >3---<s:property value= "eapricejsonstr"/>---</div>
<div >4---<s:property value= "#action. Eapricejsonstr"/>---</div>
<div >5---<s:property value= "#request. Eapricejsonstr"/>---</div> can

Stack Context: Parameters, request, session, application, PageContext these Web container built-in objects, there is the page through <s:set/>< A temporary variable that is set by s:iterator/> and other tags.

  First, use the struts tag to get: <s:property value= "#session. SessionID"/>
Second, <%=request.getsession.getattribute ("SessionID");> session is also one of the built-in objects, you can directly use the session, More convenient than request.getsession, can also be written <%=session.getattribute ("SessionID");>
Three, El expression get: ${sessionscope.sessionid}

The most direct way to view is to add <s:debug></s:debug> to the page, and then open the page in a browser to see the link like Debug. Click inside to see what the two stores are. Very convenient.

Using <s:debug></s:debug>, you can find three key:action, request, attr in the Stack context.

We can also get values on the Web front end with these three keys. For example, there is a parameter value of param in the action. In addition to this page get:

${param},

${action.param},

<s:property value= "param"/>,

<s:property value= "#action. param"/>

<s:property value= "#request. param"/> But not so ${Request.param}

Special Note: El expressions cannot be used in struts2 tags: <s:property value= "${param}"/> is wrong : accordingto TLD or attribute directive In tag file, attribute value does not accept anyexpressions.

5. Output an expression through the JSP.

Parameters:

<%=request.getparameter (paramname)%>.

Property value:

<%=request.getattribute ("AttributeName")%>

Go + summarize!! about how JSP pages are valued

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.