jsp页面从服务器接收数据,并且将数据经选择后提交到服务器


jsp从servlet接收了一个数组,想利用select让用户选择后将选择后的结果提交回servlet,结果在向servlet提交过程中参数一直传不过去,求大神帮忙解决一下


<! --classselect.jsp-->
 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

    <title>My JSP 'banjishumu.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>
  <body>
  <%String[] a = (String[])request.getSession().getAttribute("a");%>
  <%int i=0; %>
  <form action="Main" method="post" name="form2">
  请选择班级名称:<select name="ok1">
<% while(a[i]!=null)
  {%>
  <option value='<%=a[i] %>'><%  out.println(a[i]);i++;%></option>
  <%  }   %>
  </select>
  <input type="submit" name="submit1" value="确认"/></form>
  </body>
</html>

//Main.java
public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
    response.setContentType("text/html;charset=utf-8");
        String adname=request.getParameter("adname");
        String ok1=request.getParameter("ok1");
        String []a=new String[100];
        request.getSession().setAttribute("a",a); 
        request.getRequestDispatcher("classselect.jsp").forward(request, response); 
        }
查看全部
u014644192
天空的启明星
2015/06/14 08:09
  • 数据
  • 参数
  • 点赞
  • 收藏
  • 回答
    私信

4个回复