想问个getParameter()去参数只能取到null的问题。
本身是一个特别简单的页面,想从input中取到值,但是不知道为什么调试的时候发现getParameter都只能取到null。在网上查了相关问题几乎都是因为form里加了“enctype="multipart/form-data”才取不到值的,但是我这个代码里没有加这条也取不到。而且之前同个环境用相同方法取值的模块就没有这种问题。出问题的具体代码如下:Rename.jsp:
<form name="rename" method="POST" action="Rename">
<b>重命名</b><br>
  <input type="text" name=“address”/><br>
  <input type="text" name="newaddress"/><br>
<input type="submit" name="submit" value="submit"><br>
</form>Rename.java:
public void doPost(HttpServletRequest rq,HttpServletResponse rp) throws ServletException,IOException,Exception{
        progress(rq,rp);
}
public void progress(HttpServletRequest rq,HttpServletResponse rp) throws ServletException,IOException,Exception{
        rq.setCharacterEncoding("gb2312");
        rp.setContentType(contentType);               
        String fradd = rq.getParameter("address");
        String toadd = rq.getParameter("newaddress");       
        HDFSOperation operation = new HDFSOperation();
        operation.Rename(fradd, toadd);                    
    }HDFSOperation.java:
    public void Rename(String fradd,String toadd) throws IOException{
        Configuration conf = new Configuration();
        String basic = "hdfs://localhost:9000/user";
        Path basicpath = new Path(basic);
        Path frpath = new Path(basic + fradd);
        Path topath = new Path(basic + toadd);
        FileSystem fs = FileSystem.get(conf);
        fs.rename(frpath, topath);
    }没问题的模块(之一)代码如下:
UploadFile.jsp<body>
<form name="upload" method="POST" action="UploadFile">
<b>本地路径</b><br>
<input type="text" name="LocalAddress"/><br><br>
<b>HDFS路径</b><br>
<input type="text" name="HDFSAddress"/><br><br>
<input type="submit" name="submit" value="提交"/></form>
</body>UploadFile.java
public void doPost(HttpServletRequest rq,HttpServletResponse rp) throws{
                progress(rp,rq);
}
public void progress(HttpServletRequest rq,HttpServletResponse rp) throws ServletException,IOException,Exception{ rq.setCharacterEncoding("gb2312");
String local = rq.getParameter("LocalAddress");
String hdfs = rq.getParameter("HDFSAddress");

rp.setContentType(contentType);

HDFSOperation operation = new HDFSOperation();
operation.uploadFile(local,hdfs);
rp.sendRedirect("success.html");
}
}public void uploadFile(String local,String hdfs) throws FileNotFoundException,IOException{
//上传到hdfs
InputStream in = new BufferedInputStream(new FileInputStream(local));
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create(hdfs),conf);
OutputStream out = fs.create(new Path(hdfs), new Progressable() {
public void progress() {
System.out.print(".");
}
});
IOUtils.copyBytes(in, out, 4096, true);

}
感谢各位高手啦!

解决方案 »

  1.   

    如果配置没错的,话,是可以得到值的,保证编正确完成,配置正确public class Rename extends HttpServlet { /**
     * 
     */
    private static final long serialVersionUID = 7824601302184525903L; public void doPost(HttpServletRequest rq, HttpServletResponse rp)
    throws ServletException, IOException {
    try {
    progress(rq, rp);
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    } public void progress(HttpServletRequest rq, HttpServletResponse rp)
    throws ServletException, IOException, Exception {
    rq.setCharacterEncoding("utf-8");
    rp.setContentType("text/html");
    String fradd = rq.getParameter("address");
    String toadd = rq.getParameter("newaddress");
    rp.getWriter().write(toadd);
    }
    }
      

  2.   


    谢谢!!!!!!
    我也知道按理来说应该有值,但是就是为null当时找了经验比较多的人来帮忙调试也没看出来什么毛病。。配置应该改哪呢?
      

  3.   

    本帖最后由 net_lover 于 2013-04-29 20:50:31 编辑
      

  4.   

    本帖最后由 net_lover 于 2013-04-30 09:26:22 编辑