开发者

How to give alert message in servlet and redirected it to jsp page

开发者 https://www.devze.com 2023-03-01 22:56 出处:网络
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 Servle

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..');");
%>
0

精彩评论

暂无评论...
验证码 换一张
取 消