当前位置: 代码迷 >> Java Web开发 >> 表单Value赋值为脚本变量的有关问题,
  详细解决方案

表单Value赋值为脚本变量的有关问题,

热度:60   发布时间:2016-04-17 14:39:03.0
表单Value赋值为脚本变量的问题,急!
<jsp:include   page= "2.jsp "   flush= "true "/>  
<%  
Enumeration   e=request.getAttributeNames();  
while(e.hasMoreElements()){  
String   attributeName=(String)e.nextElement();  
String   attributeValue=(String)request.getAttribute(attributeName);
out.print( "变量名称: "+attributeName);  
out.print( "变量内容: "+attributeValue+ " <BR> ");  
}  
%>  
<form   method= "POST "   action= "login.jsp ">
<input   type= "hidden "   name= "Seed "   >
<input   type= "submit "   value= "Submit "   name= "submit "   >
</form>
我想把隐藏表单Seed的Value赋值为脚本里的变量attributeValue,怎么办?

------解决方案--------------------
你把定义String attributeValue放在while外边就可以了

String attributeName= " ";
String attributeValue= " ";
Enumeration e=request.getAttributeNames();
while(e.hasMoreElements()){
attributeName=(String)e.nextElement();
attributeValue=(String)request.getAttribute(attributeName);
out.print( "变量名称: "+attributeName);
out.print( "变量内容: "+attributeValue+ " <BR> ");
}


<form method= "POST " action= "login.jsp ">
<input type= "hidden " name= "Seed " value= " <%=attributeValue%> " >
<input type= "submit " value= "Submit " name= "submit " >
</form>
  相关解决方案