discussion_new.jsp
이라는 서블릿에 매개 변수를 전달하려고 시도하는 jsp 파일이 있지만 값이 전달되지 않습니다. 도움을 받으십시오. 다음 코드를 첨부합니다.jsp에서 서블릿으로 값을 전달하려고 시도했습니다
<%@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>
그리고 여기 Servlet
코드 : 여기
는 discussion_new.jsp
입니다
@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>
}
가 및 속성 값을, 내가 확인 한 SQL 구문에 오류가없고, 나는 제거했다 코드에서 추가 주석. 누군가가
이
@ Jaitheradevi - 예, 시도해 보았습니다. 이제 작동합니다. 다시는 실수하지 않을 것입니다. – user3532953
@ Bills- 네, 값을 인쇄 해 보았습니다. 실제로 전달되지 않았습니다. 실제로 작동하지 않는 이유는 p1.executeUpdate()입니다. – user3532953