Lina
Lina

Reputation: 315

How to get same JSP page after click on alert

I am using alert popup to show a meesage on jsp page. So when user clicks on alert popup, I would want to stay user on the same jsp page. But I am getting an error 404:resource not found.

else if(ExstingUser!=null)
             {
                 out.println("<script type=\"text/javascript\">");
                 out.println("alert('User Name is already exist');");
                 out.println("location='/index.jsp';");
                 out.println("</script>");
                 //response.sendRedirect("/index.jsp");   
             }

I also tried with response.sendredirect (), But it's still not working. Could anyone help me out with my issue.

Upvotes: 0

Views: 466

Answers (1)

sForSujit
sForSujit

Reputation: 985

You have done a small mistake, Just remove slash(/) from the location attibute

PrintWriter out = response.getWriter();
         out.println("<script type=\"text/javascript\">");
         out.println("alert('User Name is already exist');");
         out.println("location='index.jsp';");
         out.println("</script>");

Make the changes in your web.xml as below : You need to make correction in url-pattern tag.

  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>SaveInfo</display-name>
    <servlet-name>SaveInfo</servlet-name>
    <servlet-class>com.simext.register.SaveInfo</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>SaveInfo</servlet-name>
    <url-pattern>/SaveInfo</url-pattern>
  </servlet-mapping>

That's it.

Upvotes: 1

Related Questions