天空的启明星 2015-06-14 08:09 采纳率: 0%
浏览 1858

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条回答

  • 生活没有if-else 2015-06-14 08:27
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误