Reputation: 1537
I am working on a JSP/servlet application.
I want to pop up a message alert box in JSP/servlet after inserting user data to database table.
Upvotes: 3
Views: 41051
Reputation: 21
try this within jsp to pop show message after inserting value into db
<%
String s1=request.getParameter("username");
String s2=request.getParameter("passward");
int a=0;
try{
a=st.executeUpdate("insert into tablename values('"+s1+"','"+s2+"')");
if(a==1){
%>
<p>well come for you</p>
<%
}
else{
%>
<p>not well come for you</p>
<% }
}
}catch(Exception e){
e.printStackTrace();
}
%>
Upvotes: 0
Reputation: 319
after data insert in DB you need to use
request.setAttribute("alertMsg", "data add sucess");
then redirect to jsp by using RequestDispatcher
RequestDispatcher rd=request.getRequestDispatcher("/index.jsp");
rd.include(request, response);
Now in jsp use scriptlet tag like
<% String message = (String)request.getAttribute("alertMsg");%>
And you will get a alert message.
Now in javascript alert show like this
<script type="text/javascript">
var msg = "<%=message%>";
alert(msg);
</script>
Upvotes: 6