Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating a recipe database (Step 3: Creating a webpage to call the webservices and display results)

 
Shakur Burton
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Continuing from "Creating a recipe database (Step 2: Creting webservices to access the database)

I am now trying to create a file called recipe.html to provide button access (and input fields and parameters for each of the web services I have created).

I am also aiming to include a set of buttons to
Retrieve all recipes (all values in the table from my 'recipe' MySQL code.)
Retrieve a recipe by ID (retrieve a value by the variable RecipeID in the table from my 'recipe' MySQL code.)
Retrieve all recipes by serving size (all values by the variable NumOfServings in the table from my 'recipe' MySQL code.)

This is what I have created so far:



The problem is is that it isn't correct and does not effectively correspond tothe code I am providing below, as it either does compile and ultimately does not do what it's supposed to do,
or that it generates a 500 - level internal service error. I know I've talked about this before, but not in this much detail... I apologize for that.
Now, most importantly, I am trying to get this code to cooperate and compile properly alongside with the following sets of code...

1) MySQL code for Recipe database...


2) Java code for Recipe database:


3) These are the URLs I'm trying to get it to correspond with:

To retrieve all recipes (aka all values in my MySQL 'recipe' database).
http://localhost:8080/recipewebapp/reciperesources/rp1/recipes

To retrieve recipes by id (aka all values in my MySQL 'recipe' database by a specific given ID).
http://localhost:8080/recipewebapp/reciperesources/rp1/recipes/2

To retrieve recipes by numOfServings (greater than or equal to the parameter) (aka all values in MySQL 'recipe' database by a specfic variable called 'NumOfServings').
http://localhost:8080/recipewebapp/reciperesources/rp1/recipes/recipe?serving s=6

I there anything at all that I need to modify or fix in the index to match what's in both my MySQL and Java code? I seriously need some help in getting this right so I can have it up and running ASAP.
Thank you.
 
Shakur Burton
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Again, code that is not properly indented won't likely get many readers.


How do I indent this code, then? I want this code to be readable to those willing to answer my question...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry but blocks like this:
are not easily readable without indentation. Indentation is as much a tool for readability as it is one to visually verify the correctness of the structure. It is as important, if not more so, than following proper naming conventions.

You asked for way to improve your code; this is a big one. If you are serious about your craft, then the code above is simply not acceptable.
 
Shakur Burton
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Better. Now, what specific compilation errors are you getting? Please post verbatim using code tags to preserve formatting.
 
Shakur Burton
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Better. Now, what specific compilation errors are you getting? Please post verbatim using code tags to preserve formatting.


When I go to the following links to see if MySQL stored the values I entered, I keep getting nothing but 404 errors in all of these links...
http://localhost:8080/recipewebapp/reciperesources/rp1/recipes
http://localhost:8080/recipewebapp/reciperesources/rp1/recipes/2
http://localhost:8080/recipewebapp/reciperesources/rp1/recipes/recipe?servings=6

There's also the fact that although my code compiled successfully, I keep getting these results, which aren't even linked to my 404 errors, as they are all 500 Internal Service Errors, as shown in this image I've attached to this post.

I also have this error reported by my Tomcat8 program, which is what is used to compile and implement my RecipeServices.java code generating this error:
07-Nov-2014 17:27:16.481 SEVERE [localhost-startStop-1]
org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource Unable to process web resource [/WEB-INF/classes/com/cs330/meals/RecipeServices.class] for annotations
org.apache.tomcat.util.bcel.classfile.ClassFormatException: It is not a Java .class file


And I'd like to remind myself that I did modify the MySQL code to retrieve my table values from MySQL correctly.
Do you have any suggestions?
No_Progress_Whatsoever.PNG
[Thumbnail for No_Progress_Whatsoever.PNG]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource Unable to process web resource [/WEB-INF/classes/com/cs330/meals/RecipeServices.class] for annotations
org.apache.tomcat.util.bcel.classfile.ClassFormatException: It is not a Java .class file

That has nothing at all to do with your SQL syntax or anything else in your code. Your class files (or at least this file) is hosed. Nothing at all is going to work if your class files aren't good.

How are you building these class files and getting them into their destination?
 
Shakur Burton
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This image I have attached lists all of the errors I have encountered so far... It's in the right directory. However, it thinks these imports don't exist. What the hell?


EDIT - I have confirmed that CMD does not think my class files even exist at all. Any of them. Nor can it find required symbols on certain bits of code, hence all of the errors I keep getting.
7_Errors.PNG
[Thumbnail for 7_Errors.PNG]
 
Shakur Burton
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource Unable to process web resource [/WEB-INF/classes/com/cs330/meals/RecipeServices.class] for annotations
org.apache.tomcat.util.bcel.classfile.ClassFormatException: It is not a Java .class file

That has nothing at all to do with your SQL syntax or anything else in your code. Your class files (or at least this file) is hosed. Nothing at all is going to work if your class files aren't good.

How are you building these class files and getting them into their destination?


I don't know - I could really use some help on how to build them properly. I think that's what's killing me here.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If they are not compiling, how are you getting class files in the first place?

And please do not include screen shots -- they aren't searchable. Please use text.
 
Shakur Burton
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry if I haven't responded, but I don't need to be complaining... I needed to do some research on the errors I found in my programming...

As it is, my programs weren't compiling properly, due to certain classpaths not being set in CMD. It's hard to explain for me at this time. I hope you understand and I'm sorry to waste your time like this without better questions to ask in order to solve my issues at the moment.

EDIT - I managed to get my code working with minimal errors... I had to basic reset some classpaths to certain programs that operate in tandem with my Java code that contain features that only work with these programs:
Jersey JAX-­‐RS 2.0.1 RI Bundle - which has you enter at CMD set CLASSPATH=%CLASSPATH%;c:\progs\jaxrsri\api\javax.ws.rs-api-2.0.1.jar in order to activate certain .jar file not found in Java, but compatible with it.

I also found that in CMD, I wasn't setting my classpath for my Java code to this: set CLASSPATH=c:\progs\;c:\progs\<nameOfMySQLjarfile>.jar, which is my MySQL .jar compilation file(s).

Most of that would explain why my Java code wasn't compiling at first. I have resolved all of that, thankfully.

Now, I'm onto my next problem - and this time, I can better explain it:

Although my java code compiles successfully in CMD and takes me to the web service I have successfully created, I'm still having some issues. They come from this index.html file I have created and edited to work properly here:



I have been working on my RecipeServices Code, piece by piece and managed to get my Retrieve All Recipes and Retrieve A Recipe By ID methods working just fine. However, when trying to get my Retrieve by NumOfServings code working, I keep running into this error in my index.html code at this particular line here...



The error I am getting is an Uncaught Type Error - Undefined is not a function... This particular error is what is causing my web-service program to not function properly, as well as not return anything when I try to go retrieve something by the int variable NumOfServings in my this snippet of my java code...



If there is nothing wrong with my MySQL code, a it corresponded to this perfectly, nor my java code, then it must be something wrong with my index.html code. Unless it is something going undefined in my corresponding java code, that is...
 
Shakur Burton
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After doing some research and reworking on my code for a while, I managed to get it up and running, I have found my problem with this program I am trying to create - In my webserver, when I try to Retrieve a value from my MySQL recipe table by the int variable, NumOfServings, no value is shown to have been returned, despite all of the following:
1) Successful compilation of the java code I have posted here.
2) Successful compilation of my index.html file.
3) The webserver I have created to work with this code is running successfully, despite not returning anything in my "Retrieve by NumOfServings method.

Here are the code snippets I am working with to get the situation dealt with: This is for the specific method in Java that's causing me trouble.



Also, here is the snippet of code from my index.html file that the java code corresponds to... Which I have modified to get rid of any previous errors...



Now, both of these snippets of code compile perfectly when I go to run them, but when I go to run them in my web - server to retrieve something within the parameter of NumOfServings, nothing gets returned, despite successful compilation. What exactly is going on here and are there any other suggetions that can be offered on how to tackle this issue I'm having more effectively?

Thank You.
 
Paul Clapham
Sheriff
Posts: 21567
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not particularly up to speed on this type of web service, so perhaps I'm misunderstanding. Could you explain how the URL parameter "servings" from this url:

"http://localhost:8080/recipewebapp/reciperesources/rp1/recipes/recipe?servings="+inputTagName

gets mapped to the query parameter "NumOfServings" which you declare here:



?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please indent your code.
 
Shakur Burton
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I'm not particularly up to speed on this type of web service, so perhaps I'm misunderstanding. Could you explain how the URL parameter "servings" from this url:

"http://localhost:8080/recipewebapp/reciperesources/rp1/recipes/recipe?servings="+inputTagName

gets mapped to the query parameter "NumOfServings" which you declare here:



?


The http code clearly got mapped to this snippet of MySQL code here, if I'm not mistaken...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic