문제

am i implementing the post redirect get approach in java web. i have this index.jsp which i can add information to database.

<form action="servlet" method="post>
<input type="text" placeholder="itemname"/>
<input type="text" placeholder="itemprice"/>
<input type="submit" value="add item"/>
</form>

and in servlet i process the username and password

//returns a boolean if success or not
if(processItem(itemname,itemprice)){
     response.sendRedirect("secondservlet?ADD=success");
}

and in the secondservlet

if(request.getParameter("ADD").equals("SUCCESS"))
 request.getRequestDispatcher("success.jsp").forward(request,response);

am i doing it right?

도움이 되었습니까?

해결책

am i doing it right?

You are sending a POST, then redirecting, which results in a GET. If that is what you were trying to do, then yes, you are doing it right.

Note that your second servlet should probably check if getParameter(..) returns null. You might get to the second servlet from some other call that doesn't include any request parameters.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top