Mysql 尝试将值从jsp传递到servlet

Mysql 尝试将值从jsp传递到servlet,mysql,jsp,servlets,Mysql,Jsp,Servlets,我有一个jsp文件discussion_new.jsp,通过它我试图将参数传递给一个名为DiscussionServlet的servlet,但是没有传递值,请帮助,我附加了以下代码 以下是讨论_new.jsp: sql语法和属性值没有错误,我已经检查过了,我也从代码中删除了额外的注释。希望有人能帮助你,你的代码看起来很好,请确认你得到了servlet中的post数据,然后像这样打印值到控制台 字符串post_title=request.getParameterpost-title; 字符串pos

我有一个jsp文件discussion_new.jsp,通过它我试图将参数传递给一个名为DiscussionServlet的servlet,但是没有传递值,请帮助,我附加了以下代码

以下是讨论_new.jsp:


sql语法和属性值没有错误,我已经检查过了,我也从代码中删除了额外的注释。希望有人能帮助你,你的代码看起来很好,请确认你得到了servlet中的post数据,然后像这样打印值到控制台 字符串post_title=request.getParameterpost-title; 字符串post_detail=request.getParameterpost-detail; System.out.printlnpost\u标题; System.out.printlnpost\u详图;
然后检查控制台是否获得值

您的代码是完美的,并且值也会传递给servlet,我认为您犯的唯一错误是,您试图将接收到的值插入数据库,但缺少p1.executeUpdate,因此,如果您希望将接收到的值存储在包含p1.executeUpdate的数据库中,它将正常工作

@Jaitheradevi是的,我试过了,现在可以用了,我不会再犯这个错误了。@Bills-是的,我试过打印值,结果通过了,我实际上没有写p1.executeUpdate,这就是为什么它不能用的原因。
 <%@page contentType="text/html" pageEncoding="UTF-8"%>
 <!DOCTYPE html>

 <html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>

</head>
<body>
<h1 align="center"> Start a New Discussion</h1>
  <div id="right-container">
<form action="DiscussionServlet" method="post">
       <br>
     <h1 align="left">Discussion Title</h1>
  <textarea name="post-title" id="post-title" rows ="1" cols="90" height="50"   
    width="200">
                  </textarea>
            <h1 align="left">Discussion Content</h1>
   <textarea name="post-detail" id="post-detail" rows="18" cols="90" height="50" 
     width="200">
  </textarea>

<input id="button-submit" type="submit" value="Post" onclick="return confirm('Do                
      you really want to make this post?');" name="submit"/>        
     </form>
  </div>

   </body>
    </html>
@WebServlet(name = "DiscussionServlet", urlPatterns = {"/DiscussionServlet"})
public class DiscussionServlet extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    HttpSession s=request.getSession();
   String u_id= (String) s.getAttribute("u_id");
   String post_title=request.getParameter("post-title");
   String post_detail=request.getParameter("post-detail");


    PreparedStatement p1=null;
    try {
         Connection c1=ConnectionClass.getConnected();
         p1=c1.prepareStatement("insert into     
     discuss(id,disc_title,disc_content)values(?,?,?)");
         p1.setString(1, u_id);
         p1.setString(2, post_title);
         p1.setString(3, post_detail);    
    }
    catch(Exception e)
    {

    }
    finally {            
        out.close();
    }
}

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);
}


   @Override
public String getServletInfo() {
    return "Short description";
}// </editor-fold>
}