Java and JS using hidden tags to pass parameters

Source: Internet
Author: User

In web development, the server is often used to deal with data from the front end.

Just touch the Web, the parameter pass is not too clear, oneself also through a small management system to learn a bit.

The following is a brief talk about the parameters in the JSP, HTML delivery. is actually using the hidden tag, type= "hidden"


. Java servlet uploads to Web page

Request.setattribute ("Sex", sex);


The. JSP page first determines whether the parameter exists

In fact, this piece of code can not be written, but for the sake of practice, we write first

if (Request.getattribute ("sex") = null) {String sex = request.getattribute ("Sex"). toString (); Request.setattribute ("Sex", sex); }


Set a Label property in the layout to hidden that is, hide the label, is not visible on the interface

Label Assignment ${sex} sex is our key value above setattribute (Key,value)

<input type= "hidden" id= "Sex_hidden" name= "Sex_hidden" Value= ' ${sex} ' >

This is the value from Java->js.

To take a value in the script module

The following statement shows a drop-down list of three options (all, male, female)

A list can be dynamically assigned based on data obtained from Java code

Since the drop-down list will be returned to the original state each time the interface is refreshed, the default value of the list can be resolved by this

<script type= "Text/javascript" > var sex = document.getElementById ("Sex_hidden"). Value;        for (var i=0; i<3; i++) {var sex2 = document.getElementById ("Sex"). Options[i].value;            if (sex = = Sex2) {document.getElementById ("sex"). Options[i].selected = true;        Break }}</script>

Paste Sheet

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/11/wKiom1XcYhXCzFdxAATYrOD41jc007.jpg "title=" Qq20150825203837.png "alt=" Wkiom1xcyhxczfdxaatyrod41jc007.jpg "/>

This article is from the "climb over the mountains to see the Sea" blog, please be sure to keep this source http://670176656.blog.51cto.com/4500575/1688222

Java and JS using hidden tags to pass parameters

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.