How to give alert message in servlet and redirected it to jsp page
i am developing some kind of pubsub application,so when a user subscribe to particular entity then he receive a alert for successful subscription and redirect o开发者_如何学Cn the same page.
In Servlet
session.setAttribute("Login_Expired","Expired") ;
response.sendRedirect("jsp/page.jsp");
In JSP
<%
String strExpired = (String) session.getAttribute("Login_Expired");
if (strExpired.equals("Expired")){
out.print("alert('Password expired, please update your password..');");
}
%>
Add an attribute in request from servlet and forward request to jsp on jsp use following
request.setAttribute("subscribed",true);
on jsp , in javascript
if(${subscribed == 'true'}){
alert("Peep Peep..");
}
In servlet
String strExpired = (String) session.getAttribute("Login_Expired");
response.sendRedirect("jsp/page.jsp");
In jsp
<%
String strExpired = (String) session.getAttribute("Login_Expired");
out.print("alert('Password expired, please update your password..');");
%>
精彩评论