• Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet XML Transformation problem  RSS feed

 
Mattew Lee
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trying to use the following Servlet to transform a XML to HTML but GlassFish server doesn't show any web page and reads this error " The requested resource is not available".
I guess the problem is from the address of XML and XSL files but I don't know where I must put them in my project. I use NetBeans IDE.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66158
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to give the path to the file. Servlets have no concept of a "current directory" so your relative paths could be resolving to anywhere, but unlikely the correct location.
 
Rajani Gummadi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:You need to give the path to the file. Servlets have no concept of a "current directory" so your relative paths could be resolving to anywhere, but unlikely the correct location.


When you say path of the file, I believe, you meant the relative path from the context. Is that right?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66158
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not the way that the poster has written his code. The file I/O system needs the absolute path to the files. It doesn't know anything about the context.

If the poster wants to switch to using ServletContext.getResourceAsStream() and the files are within the context, then context-relative paths would be fine.
 
Mattew Lee
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Not the way that the poster has written his code. The file I/O system needs the absolute path to the files. It doesn't know anything about the context.

If the poster wants to switch to using ServletContext.getResourceAsStream() and the files are within the context, then context-relative paths would be fine.


Would you please tell me where in my code I must add this statement and if I must make any other changes? And what do you mean by saying "within the context" is it like within the project directories? ( where do you suggest I place XSL and XML file? )
Thanks.

Cheers,
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66158
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to learn web app concepts. I'd suggest reading through the Servlet Specification. It's an easier read than you might imagine.

But yes, if the file lies within the app context, you can use a context-relative path. Otherwise, you'll need the full absolute file path.
 
Mattew Lee
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everybody for guides and recommendations.
I made the following code base on your recommendation but still get "Resource not available" message when I run the project through NetBeans/GlassFish
I added both XML/XSL files in XML directory and files are accessible via url like this: http://localhost:80/myProject/xml/xmlFilename.xml

 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!