这个代码是正确的,但是如果我加上用//屏蔽的代码,读到的test内容是null,请问我如何将表格中的内容传过去,并且读出来

解决方案 »

  1.   

    以下是html代码
    <html>
      <head>
        <title>movie</title>

        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="this is my page">
        <meta http-equiv="content-type" content="text/html; charset=GB2312">
        
        <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
      </head>
        <body>
         <h2>select from available movies</h2>
         <form action = movie method = post>
         <select name = "movies" size = "5" multiple>
         <option> air force </option>
         <option> happy gilmore </option>
         <option> so i married an axe murderer</option>
         <option> austin powers </option>
         <option> pure luck </option>
         </select><br>
         <input type = "submit" name = "add" value = "add movies">
         </form>
       </body>
    </html>
      

  2.   

    web.xml代码<?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4" 
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
      <servlet>
        <description>This is the description of my J2EE component</description>
        <display-name>This is the display name of my J2EE component</display-name>
        <servlet-name>movie</servlet-name>
        <servlet-class>test.movie</servlet-class>
      </servlet>
     
      <servlet-mapping>
        <servlet-name>movie</servlet-name>
        <url-pattern>/movie</url-pattern>
      </servlet-mapping>
    </web-app>
      

  3.   

    那得到的字符串就是空值,如果你处理Null值可能会抛出空指针异常。
      

  4.   

    对于上面3句屏蔽的话,我后来试过了,如果我把2个“测试”改成英文,并把
    doGet方法中的这段
    for(int x= 0; x < movies.length; x++){
    out.println(movies[x] + "<br>");
    }改成
    for(int x= 0; x < movies.length; x++){
    out.println(new String(movies[x].getBytes("iso-8859-1"), "gbk") + "<br>");
    }
      

  5.   

    如果改成上面那样,就读的到test里面的内容了,我觉得jsp最终要转化成servlet,所以request是读的到数据的,至于,为什么他能读到从servlet(用于控制的)本身里面定义的表单数据,以及request的工作原理,我还不是很清楚,这可能设计到一些协议问题吧,等我知道了就把答案贴出来。
    谢谢你的回帖。