JSP向servlet传值

1.直接往input中读取(form 的action用该servlet,servlet用request.getAttribute获得值) 

jsp:
< input type = " text "  name = " title "   >

servlet:
String title
= request.getAttribute( " title " );

 

 

 

 

2.带hidden的input

jsp:
< input type = " hidden "  name = " title "  value " title_value " >

servlet:
String title
=  request.getAttribute( " title " );

 

 

 

3.将checkbox的值传到servlet

代码
jsp:
<%
  
for ( int  i = 1 ;i < N;i ++ ) {
%>
< input type = " checkbox "  name = " checkbox " +<%= %>    value =<%= %>   />
<%  i ++ ; }  %>

servlet:
String ini;
for  ( int  i  =   1 ; i  <  N; i ++ ) {
    ini
= request.getParameter( " checkbox " + i); 
  
if (ini != null ){                      // 被选中的checkbox执行相关操作
    ......
    }

 

     

你可能感兴趣的:(servlet)