Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to display and delete products in a JSP file  RSS feed

 
Jonathan Mitchell
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I'm new here and I don't know where else to turn. I am trying to update and delete products from a JSP page but am having a hard time getting the code to work. I keep getting errors and my program won't run. I'm confused and don't know what to do. I really need some help. My Index.jsp page works, but everything else is messed up. Below is my code.

index.jsp


Products.jsp



Product.jsp


confirm_product_delete.jsp


product.java

ProductIO.java
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Much more important than showing reams of unformatted code (please be sure to UseCodeTags -- I added them to your post for you) would be to show us the error messages that you are getting. Please also read ItDoesntWorkIsUseless. Providing more details about the errors helps people help you better.
 
Jonathan Mitchell
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, I am new this forum. I just need to know what I am doing wrong regarding my code. I tried to look for similar codes that could help me on how to set up my code but can't find any.
error.png
[Thumbnail for error.png]
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does a "cart.jsp" exist? None of what you posted indicates that it does. If it does, where in the file system is it?
 
Jonathan Mitchell
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried editing my code from another code. I realize that I didn't need the cart.jsp, but this code is complicated. Here's the layout on how the code should look like. I know how to set up the index.jsp page, but it is the rest of the code that contains errors. For example when I try to press the "Add Product" page on the products.jsp page to gain access to the product.jsp page, nothing happens.
Index_Products.png
[Thumbnail for Index_Products.png]
product_delete.png
[Thumbnail for product_delete.png]
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post the errors you are getting (with full stack traces).
 
Jonathan Mitchell
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Netbeans & Apache Tomcat. When I look at the code in Netbeans, there is no red explanation marks to suggest that there are errors, But when I run it, it appears in good shape. All I get is the 404 error pages or buttons that won't respond. I already posted my code in my first post. In other words, the full stacks don't seem to be the problem.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The one 404 you posted is explained by that page not existing. If there are other 404s, post the URLs for which they are happening.

As to buttons not working, I note that there are no "form" tags in either Products.jsp or delete.jsp - so any form functionality (like form submission) would not work.
 
Jonathan Mitchell
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I fixed the form tags on the product.jsp and product.jsp pages and updated the code. The View Products button on the product.jsp page works fine, but my Update Products page still won't function properly.

Also I still need to figure out how to add and delete the products. I get the exact same 404 url on the pages that are not working.

For the first one, when I click Delete, it needs to go to the delete.jsp. But I get errors. I need something like "deleteProduct?productCode=8601" to show up and I can't figure out how to do it.

<tr valign="top">
<td>86 (the band) - True Life Songs and Pictures</td>
<td>$14.95</td>
<td><a href="<%=response.encodeURL("cart?productCode=8601")%>">Edit</a></td>
<td><a href="<%=response.encodeURL("cart?productCode=8601")%>">Delete</a></td>
</tr>

OR

<tr valign="top">
<td>86 (the band) - True Life Songs and Pictures</td>
<td>$14.95</td>
<td><a href="<%=response.encodeURL("product.jsp")%>">Edit</a></td>
<td><a href="<%=response.encodeURL("confirm_product_delete.jsp")%>">Delete</a></td>
</tr>


404 error messages
=======================================================================
HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: /confirm_product_delete.jsp(18,28) The function getPriceFormat must be used with a prefix when a default namespace is not specified
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
org.apache.jasper.compiler.Validator$ValidateVisitor$1FVVisitor.visit(Validator.java:1479)
org.apache.jasper.compiler.ELNode$Function.accept(ELNode.java:129)
org.apache.jasper.compiler.ELNode$Nodes.visit(ELNode.java:200)
org.apache.jasper.compiler.ELNode$Visitor.visit(ELNode.java:242)
org.apache.jasper.compiler.ELNode$Root.accept(ELNode.java:56)
org.apache.jasper.compiler.ELNode$Nodes.visit(ELNode.java:200)
org.apache.jasper.compiler.Validator$ValidateVisitor.validateFunctions(Validator.java:1504)
org.apache.jasper.compiler.Validator$ValidateVisitor.prepareExpression(Validator.java:1509)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:726)
org.apache.jasper.compiler.Node$ELExpression.accept(Node.java:958)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2417)
org.apache.jasper.compiler.Node$Root.accept(Node.java:495)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1736)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:183)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:332)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:299)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the future, please don't post screenshots of error messages. Post the actual text, so that it can be copied, quoted and searched.

Not knowing anything about the confirm_product_delete.jsp, there isn't much we can say about that error, except that you're apparently using the getPriceFormat method incorrectly.

I get the exact same 404 url on the pages that are not working.

So none of the JSPs are actually being found? That sounds as if they're not in the place where they are expected. That brings me back to the question where they are in the file system. The 404 error you posted indicated they were in the top-level directory; is that where they are? And is that where the respective 404 message indicates it is missing them?
 
Jonathan Mitchell
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I renamed the delete.jsp file to confirm_product_delete.jsp I'm still lost on the 404 pages.

Also, do I need a delete.java file for the delete page or an edit.java?

I forgot to add the products.jsp code on top of the page and now included it.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The name of Java classes is irrelevant - you can use whatever you like.

Please understand that it doesn't really help us help you if you say "I changed X, and now I'm getting a 404". Without knowing precisely what URL is causing a 404, and how that URL is mapped to a servlet or JSP, there is little we can advise to look into. Why don't you start by telling us the layout of all your JSP files and directories, and indicating which of those are causing errors, along with the URLs that are causing the errors?
 
Jonathan Mitchell
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main folder I am using is called "ch08cart"

when I press edit on the products page, I get the error:
http://localhost/ch08cart/editProduct?productCode=8601

HTTP Status 404 - /ch08cart/editProduct

type Status report

message /ch08cart/editProduct

description The requested resource (/ch08cart/editProduct) is not available.


When I press delete on the products page, I get the error:
http://localhost/ch08cart/deleteProduct?productCode=8601

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Wrapper cannot find servlet class music.admin.DeleteProductServlet or a class it depends on
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
java.lang.Thread.run(Thread.java:744)

root cause

java.lang.ClassNotFoundException: music.admin.DeleteProductServlet
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
java.lang.Thread.run(Thread.java:744)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.

========================================================

Here is my web.xml file
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>CartServlet</servlet-name>
<servlet-class>cart.CartServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>DisplayProductsServlet</servlet-name>
<servlet-class>music.admin.DisplayProductsServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>DisplayProductServlet</servlet-name>
<servlet-class>music.admin.DisplayProductServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>UpdateProductServlet</servlet-name>
<servlet-class>music.admin.UpdateProductServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>DeleteProductServlet</servlet-name>
<servlet-class>music.admin.DeleteProductServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>DisplayProductsServlet</servlet-name>
<url-pattern>/displayProducts</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DisplayProductServlet</servlet-name>
<url-pattern>/displayProduct</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>UpdateProductServlet</servlet-name>
<url-pattern>/updateProduct</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DeleteProductServlet</servlet-name>
<url-pattern>/deleteProduct</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>CartServlet</servlet-name>
<url-pattern>/cart</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
</web-app>
 
Jonathan Mitchell
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a link to a similar "add-delete-update" product code that I can learn from. I am still stumped. I posted my URLs.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looking at the servlet mappings, "editProduct" is not mapped - that explains the 404.

Do you have a servlet "music.admin.DeleteProductServlet", and is it where all the other servlets are?

I would advises not to have both DisplayProductsServlet and DisplayProductServlet, and also not to have both music.admin.DisplayProductsServlet and music.admin.DisplayProductServlet - those are bound to cause confusion because of their name similarity.
 
Jonathan Mitchell
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that product.jsp and products.jsp are similiar in name but those are the default names for those files. Maybe I should rename product.jsp to update.jsp.
 
Jonathan Mitchell
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I updated the delete product servlet and I am still getting problems. >:(

<tr valign="top">
<td>8601</td>
<td>86 (the band) - True Life Songs and Pictures</td>
<td>$14.95</td>
<td><a href="<%=response.encodeURL("updateProduct?productCode=8601")%>">Edit</a></td>
<td><a href="<%=response.encodeURL("deleteProduct?productCode=8601")%>">Delete</a></td>
</tr>

============================================================
HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Wrapper cannot find servlet class music.admin.DeleteProductServlet or a class it depends on
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
java.lang.Thread.run(Thread.java:744)

root cause

java.lang.ClassNotFoundException: music.admin.DeleteProductServlet
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
java.lang.Thread.run(Thread.java:744)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Do you have a servlet "music.admin.DeleteProductServlet", and is it where all the other servlets are?
 
Jonathan Mitchell
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think I do. Here is my present set:

ch08cart (folder)
Web Page
META-INF (folder)
context.xml
WEB-INF (folder)
product.txt
web.xml
confirm_product_delete.jsp
index.jsp
product.jsp
products.jsp
Configuration Files (folder)
MANIFEST.MF
context.xml
web.xml
Server Resources (folder)
Source Packages (folder)

business (folder)
Product.java
data (folder)
ProductIO.java
music (folder)
Test Packages (folder)
Libraries (folder)
Test Libraries (folder)


NOTE: I don't know how to set up spaces.
 
Jonathan Mitchell
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's my attempt to add a deleteservlet, but there are at least two errors

 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jonathan Mitchell wrote:I don't think I do.

Well, the web.xml maps that class to a URL, so if you hit that URL, and the class does not exist, then that would cause the error you're observing.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jonathan Mitchell wrote:Here's my attempt to add a deleteservlet, but there are at least two errors

If there are errors, tell us what they are, including all stack traces. We can't know what happens on your computer.
 
Jonathan Mitchell
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know you don't want any more attached photos, but here's how I have set up my project so far. I don't know where to properly put the deleteproductservlet, updateproductservlet, etc.
project.png
[Thumbnail for project.png]
 
Jonathan Mitchell
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got either "error: illegal start of expression" or "error: not a statement". There are too many to list.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know you don't want any more attached photos, but here's how I have set up my project so far. I don't know where to properly put the deleteproductservlet, updateproductservlet, etc.

For an image of a directory layout I'll make an exception :-) Generally class files go into WEB-INF/classes in a directory that corresponds to their package hierarchy, so in this case WEB-INF/classes/music/admin, but it looks like you're running Tomcat as part of your IDE, and different rules apply for that (which I don't know in detail). That's part of the reason why I generally recommend not to run your servlet container inside of an IDE, but as a standalone server, like it would later be used. That way there are no surprises.

I got either "error: illegal start of expression" or "error: not a statement". There are too many to list.

The structure is probably incorrect (missing or extra parentheses, or something like that). Without seeing the entire file we can't speculate on the reason. Look at the first line where the compiler finds a problem, and work your way forward from there.
 
Jonathan Mitchell
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added the servlets (delete, update, etc) to my code and it appeared that I finally would get my code to work but when I try to run it, I get this long message in red:

run-deploy:


Now what do I do? Also, how do I edit my first post because I want to update my code or do I have to repost all of my code again.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's something inside your IDE, next to impossible to tell why it happens.

Also, how do I edit my first post because I want to update my code or do I have to repost all of my code again.

I'm afraid that's another thing we don't like here - if you edit the earlier posts, then all subsequent posts become meaningless (because they refer to something that is no longer there). So, yes, you need to post the relevant parts again. Since this topic is getting longish, you can start a new topic for that.
 
Dave Tolls
Ranch Hand
Posts: 2506
27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Those are the servlets listed in your web.xml.
Those names (eg music.admin.DisplayProductServlet) do not match the java files in the image you posted of your directory structure (eg music/admin/displayProduct.java).
 
Jonathan Mitchell
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that I have identified my problem and have figured out how to finally run my code properly. Thank you for your help
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!