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