简体   繁体   English

我正在尝试使用getParameterName()。但是异常正在上升。如果我做错了方法,请告诉我正确的方法

[英]i am trying to use getParameterName().but exception is raising.please tell me the correct way if i am doing in wrong way

Code: 码:

protected void signup(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, NamingException ,SQLException{
    response.setContentType("text/html;charset=UTF-8");
     PrintWriter out = response.getWriter();
     try{
        String [] values = new String [10];
        Context cx=new InitialContext();
        DataSource ds=(DataSource) cx.lookup("jdbc/myDatasource");
        Connection conn=ds.getConnection();
        Enumeration en=request.getParameterNames();
        String str="insert into sign values(?,?,?)";
        PreparedStatement pos=conn.prepareStatement("str");
        for(int i=0;en.hasMoreElements();i++){
            String param=(String) en.nextElement();
            values [i]=request.getParameter("param");
            pos.setString(i,values[i]);
        }
        RequestDispatcher dss=request.getRequestDispatcher("index.jsp");
        dss.forward(request, response);
    }catch(Exception e){
        RequestDispatcher dss=request.getRequestDispatcher("error.jsp");
        dss.forward(request, response);
    }
}

As @Shekhar said, Your code should be like this 正如@Shekhar所说,您的代码应像这样

int i=0;    
while(en.hasMoreElements()){

     String param=(String) en.nextElement(); 
     values [i]=request.getParameter("param");
     pos.setString(i,values[i]);                
     i++;  
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试创建一个循环的LinkedList,请告诉我它是否是正确的方法 - I am trying to create a circular LinkedList Please tell me if its a correct way to do it 请我在这段代码中做错了什么 - Please what am i doing wrong in this code 它向我抛出错误不兼容的类型:意外的返回值——返回 10; 请更正它请注意我在哪里做错了代码? - it throws me error incompatible types: unexpected return value -- return 10; please correct it make note where i am doing wrong code? 谁能告诉我以下程序做错了什么? 我收到类似的错误<identifier expected>和“&#39;;预期” - Can anybody tell me what am i doing wrong with the following program? I am getting errors like <identifier expected> and " '; expected" JPA级联更新错误。 我做错了吗? - JPA cascade update error. Am I doing this the wrong way? 有一种有效的“合并排序”功能,但不是完全可以,有人可以告诉我我做错了什么吗? - Have a sort of working Merge Sort, but not quite, could someone tell me what I am doing wrong? 运行时错误。 请让我了解我做错了什么 - Runtime Error. Please give me understanding about what I am doing wrong 我正在用Java中的“ 0”替换Evens,我在做什么错? - I am trying to replaceEvens with a “0” in java, what am I doing wrong? 当尝试根据给定查询查找给定字符串中的子字符串计数时,有人能告诉我我在 Java 代码中做错了什么吗? - Can someone tell me what am I doing wrong here in my Java code when trying to find count of substrings in given string according to given queries? 我想从请求对象头中获取 OTP。 请让我知道我做得对还是错 - I want to get OTP from request object header. please let me know that i am doing right or wrong
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM