2 u014644192 u014644192 于 2015.06.14 16:09 提问

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); 
        }

4个回答

chentravelling
chentravelling   2015.06.14 16:27

贴一下发请求的代码!你自己也可以断点调试一下

u012216727
u012216727   Ds   Rxr 2015.06.14 16:31

你总得贴出来代码吧,光靠猜是猜不到的。

beacon_2011
beacon_2011   Rxr 2015.06.14 17:02

贴一下代码,这种情况的原因有很多

cuiwei1026522829
cuiwei1026522829   Ds   Rxr 2015.06.14 21:27

这数据是连servlet都调用不到,还是调用了,没有拿到值??

Csdn user default icon
上传中...
上传图片
插入图片