This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

read and display the content of .owl file in server

 
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI, I am new to servlets and owl api. I have installed eclipse with maven for working with owl api. I have created a maven project and tried loading owl file which returns the output

Ontology(OntologyID(OntologyIRI(<http://www.w3.org/2002/07/SteelOnto>;) VersionIRI(<http://www.w3.org/2002/07/SteelOntov0>;))) [Axioms: 2251 Logical Axioms: 1919] First 20 axioms:}

. Now I just converted the same project to dynamic web application to display the output in web. But i am unable to do. I went through the webpage but its not working for me. Please help me with this.
 
Saloon Keeper
Posts: 5880
147
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post the relevant code excerpt.
 
Gayathri Gayu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following is the code which I have tried so far.
index.html


App.java


web.xml



Not even the Hello World is printing.
 
Rancher
Posts: 2161
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is your mapping for action="App"?

You either need this


or a mapping in web.xml.
 
Gayathri Gayu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not doing the mapping in web.xml, but in java class. I am not sure what will the App refers to. Whether the app refers to my class file or the package where my class file is. I just followed the https://dzone.com/articles/become-a-master-of-java-streams-part-1-creating-st link to start working with.
 
Swastik Dey
Rancher
Posts: 2161
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you doing the mapping in java class?

//@WebServlet("/hello")  the line is commented.  

Argument here should be same as the action="" value in your html/jsp page.  So as in your html page action="App"  the mapping should be similar in the servlet class too.
 
Gayathri Gayu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry. I just uncommented the line  @WebServlet("/App") and try running the code. It throws the following error message.

 
Swastik Dey
Rancher
Posts: 2161
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it happening after you click on login button?  Do a clean build and redeploy the project.
 
Gayathri Gayu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is happening after the login button click. I did clean and run the project its giving me same error. I created new configuration for maven build and gave run on server.
 
Swastik Dey
Rancher
Posts: 2161
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create a mapping in web.xml and see if it makes any difference.
 
Gayathri Gayu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I am not sure whether the above code is correct or not. I just gave the package name in servlet class tag, and class name in servlet-name tag. Am i correct or do i have to change the servlet-name or the url-pattern

It throws the following error

 
Swastik Dey
Rancher
Posts: 2161
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


You need your fully qualified class name above, but you are giving the package name

so it should be






 
Gayathri Gayu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same error i am getting

java.lang.ClassNotFoundException: com.gayathri.HelloMaven.App

with adding App with the package name.
 
Tim Moores
Saloon Keeper
Posts: 5880
147
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I am not sure whether the above code is correct or not. I just gave the package name in servlet class tag, and class name in servlet-name tag.


servlet-class is what its name suggests, so it's missing ".App".

servlet-name can be whatever you want it to be - it's used only in web.xml, and is just a logical (not actual) name.

Edit: late to the game, I see :-)
 
Gayathri Gayu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:


I am not sure whether the above code is correct or not. I just gave the package name in servlet class tag, and class name in servlet-name tag.


servlet-class is what its name suggests, so it's missing ".App".

servlet-name can be whatever you want it to be - it's used only in web.xml, and is just a logical (not actual) name.



Thanks for the info. Now i understand about the mapping in web.xml.
 
Gayathri Gayu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a web.xml file App.class and index.html. Do i need to add anything else in my code.

Sometime i am getting the above error and sometimes this



I tried loading differnt file with html extension. I can run without any error. But i couldn't run with a class.
 
Swastik Dey
Rancher
Posts: 2161
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us the latest web.xml, and the location of your class file.
 
Gayathri Gayu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Latest web.xml file.  My class path is /home/gayathri/eclipse-workspace/HelloMaven/src/main/java/com/gayathri/HelloMaven/App.java
 
Swastik Dey
Rancher
Posts: 2161
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The above is the location of your source file.  Do you find the following folder structure WEB-INF\classes, and within this your class file?
 
Gayathri Gayu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
/home/gayathri/eclipse-workspace/HelloMaven/WebContent/WEB-INF/lib only this folder is found.
 
Swastik Dey
Rancher
Posts: 2161
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder that's where the problem is.

https://coderanch.com/t/474423/ide/ecplise-doesn-create-classes-folder
 
Gayathri Gayu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am posting my project structure.
struct.png
[Thumbnail for struct.png]
project structure.
 
Swastik Dey
Rancher
Posts: 2161
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't seem to be correct, web-inf should have classes folder.
 
Gayathri Gayu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating a project newly. So i have to configure for adding class folder in the WEB-INF following this https://coderanch.com/t/474423/ide/ecplise-doesn-create-classes-folder
 
Gayathri Gayu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also when i try configuring the build path this way

Right click on your project -> build path -> Configure build path -> click on source tab -> click on browse (Default output folder).

After browsing click on WebContent -> Select WEB-INF -> Create new folder (called classes). it will open new window.

Give folder name as classes. Click on Advanced and give path of current classes folder means WEB-INF/classes.

After doing this, eclispe will rebuild your project and classes will be genenrated at WEB-INF/classes directory.

I couldn't able to see the classes folder in WEB-INF

I have to see my classes folder by opening Navigator view (Window > Open View > Navigator) then only i can able to see the classes dir.
 
Swastik Dey
Rancher
Posts: 2161
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And does it contain the class files?
 
Gayathri Gayu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class files means my app.java file? ok files with .class extension? if so then no
stru.png
[Thumbnail for stru.png]
structure in navigation view
 
Swastik Dey
Rancher
Posts: 2161
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While creating the project are you selecting it as dynamic web project?
 
Gayathri Gayu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. I am creating dynamic web project
 
Rancher
Posts: 4325
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That structure is still wrong.
The structure under WEB-INF should be (as a base):

WEB-INF ->
   classes -> contains your .class files from your app
   lib -> contains your dependencies (ie jar files)

The image you posted shows the lib directory under the classes directory.

If you're setting up a new web project you should have no need to specify where the classes go.
The project structure should handle that for you by default.
 
Gayathri Gayu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please can you help me in how to create the new project in eclipse.
 
Swastik Dey
Rancher
Posts: 2161
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What version of eclipse are you using?
 
Gayathri Gayu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eclipse IDE for Enterprise Java Developers.

Version: 2019-06 (4.12.0)
Build id: 20190614-1200 my eclipse version
 
Swastik Dey
Rancher
Posts: 2161
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ideally it should have created the classes folder.  Try this once

1. Create a new dynamic web project (Fresh)

Once the above is done

2.Create a folder called classes under WEB-INF

3. Right click on Project->Properties->java build path

Now from Right frame select Source at the bottom it will something like Default output folder.  Browse and make it pointed to WEB-INF\classes, and see if this helps.
 
Swastik Dey
Rancher
Posts: 2161
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should be the folder structure
Untitled.png
[Thumbnail for Untitled.png]
 
Gayathri Gayu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now my folder structure is this and i am getting the following error
folderstruct.png
[Thumbnail for folderstruct.png]
new folder structure
 
Swastik Dey
Rancher
Posts: 2161
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<servlet-mapping>
       <servlet-name>App</servlet-name>
       <url-pattern>/App</url-pattern>
       <http-method>POST</http-method> //include this line in servlet-mapping section and see if this helps
   </servlet-mapping>
 
Gayathri Gayu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When trying to add the <http-method> it is throwing the error  

cvc-complex-type.2.4.a: Invalid content was found starting with element 'http-method'. One of
'{"http://xmlns.jcp.org/xml/ns/javaee":url-pattern}' is expected.

 
Swastik Dey
Rancher
Posts: 2161
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show web.xml
 
Gayathri Gayu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This was when creating project.



New project's web.xml
 
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!