0

this is deleteProduct.jsp page code. the problem is only the forward tag and the DB operation works good. i used the forward tag to go to adminProducts.jsp but the result is not correct. it shows adminProducts.jsp page content but the address bar shows deleteProduct.jsp whats the problem and how can i fix this ?

<%@ page contentType="text/html;charset=UTF-8"%>
<html>
<%@ page import="org.j2os.shine.jconnection.JDBC" %>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>delete product</title>
  </head>
  <body>
    <%
      String id = request.getParameter("id");
      out.print(id);
      JDBC mydb = new JDBC();
      mydb.login("com.mysql.jdbc.Driver","jdbc:mysql://localhost/rouyesh", "username", "password", true);
      mydb.executeSQLQuery("delete from products where id=" + id);
      mydb.commit();
    %>

    <jsp:forward page="adminProducts.jsp"></jsp:forward>
  </body>
</html>
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
Ammar Bozorgvar
  • 1,162
  • 16
  • 30

3 Answers3

3

There is no problem with forward. The contract of forwarding is to not change the URL at all as its a server side operation. If you want address bar to show the correct address, do a redirect.

Fazal
  • 2,741
  • 6
  • 27
  • 37
  • what tag should i use ? stead of forward to pass my paramiters ? – Ammar Bozorgvar Oct 16 '10 at 00:06
  • The issue depends on how many parameters you have to pass. if number is small then you should pass them as GET parameters. Otherwise you would have to pass forward as GET has a limit of parameters you can pass. For that case, either use some server memory to store parameter between requests or may be try URL rewrite – Fazal Oct 16 '10 at 19:09
2

replace

<jsp:forward page="adminProducts.jsp"></jsp:forward>

with

response.sendRedirect("adminProducts.jsp");
Ammar Bozorgvar
  • 1,162
  • 16
  • 30
0

Some times <jsp:forward page="adminProducts.jsp"></jsp:forward> works over <jsp:forward page="adminProducts.jsp"/>. Maintain closing tag separately.

Kishore
  • 111
  • 1
  • 3