SHE
SHE

Reputation: 121

JSP got http error while refreshing the page

I went through a basic tutorial about JSP and JDBC and wrote some java code in eclipse and try deploying using JSP

Here is the JSP code, basically it list all the rows (name and price) in the database and you can submit name and price by pressing the button (not implemented yet) :

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
import ="edu.neu.cs5200.s3.onlineide.applications.*, java.util.*"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link href="css/bootstrap.css" rel="stylesheet"/>
</head>
<body>
<h1>Applications</h1>
<%
  applicationsDAO dao = new applicationsDAO();
  String action=request.getParameter("action");
  String name=request.getParameter("name");
  String price=request.getParameter("price");
  String id=request.getParameter("id");

if("create".equals(action)){
      double priceD=Double.parseDouble(price);
      Application app=new Application(name, priceD);
      dao.create(app);
}

   List<Application> applications=dao.selectAll();
%>
<form action="application.jsp">

<table class="table">
    <tr>
         <td><input name="name" class="form-control"/></td>
         <td><input name="price" class="form-control"/></td>
         <td>
           <button class="btn" name="action" value="create">
              Add
           </button>
         </td>

         <td></td>

    </tr>
<%  for (Application app: applications){
%>      <tr>
           <td><%=app.getName() %></td>
           <td><%=app.getPrice()%></td>
        </tr>
<% 
  } 
%>
</table>
</form>
</body>
</html>

It originally looks like this: enter image description here

However, when I enter "Checkers" and "599" press the "add" button, it looks like this: enter image description here

Based on the tutorial, since I have not implemented the button yet, it should looks like the original page with the only change that the url changes to http://localhost:8080/OnlineIDE/application.jsp?name=Checkers&price=5.99&action=create when I enter "Checkers" and "5.99" but I got a http error. Why is that?

Upvotes: 0

Views: 39

Answers (1)

AgilePro
AgilePro

Reputation: 5598

The original was for applications.jsp, but later your link is to application.jsp. You forgot the s.

Upvotes: 1

Related Questions