File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP context problem

 
Mainak Goswami
Ranch Hand
Posts: 52
Eclipse IDE Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am creating a sample application with following code structure and the build structure as mentioned in the attachment. I am facing a strange problem.
Whenever I am typing the direct path of the URL - "http://localhost:7001/loginApp" neither the image nor the style is getting rendered. However when I am using the actual path -"http://localhost:7001/loginApp/jsp/Login.jsp" I am able to view the image in the page and the style sheet is also getting rendered.

Below is the snippet for the web.xml file:
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>

Interstingly when I am clicking on submit I am able to get the stylesheet rendered.


The jsp file snippet is :
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="../style.css" type="text/css"></link>

and


To Login please provide your Username and Password



Only when I am first hitting the URL I am not able to get the proper page.
Just for info my images and stylesheet is directly under the war file.

Can anybody please help me to provide a solution?

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.

Also, do not post screenshots to show directory hierarchy, error messages, and so on: cut and paste.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Confusingly, you do not actually show the JSP code that doesn't work.
 
Mainak Goswami
Ranch Hand
Posts: 52
Eclipse IDE Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Folder_Structure.jpg
[Thumbnail for Folder_Structure.jpg]
 
Mainak Goswami
Ranch Hand
Posts: 52
Eclipse IDE Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David. I have attached the code using the Code tag.
Can you please help me out now? Do let me know if you want any other info.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please do not quote your own text.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to build the CSS URL (and images, etc.) by using the context path. In general, I don't recommend using relative URLs, especially when using a framework--use an absolute URL that includes the context path. There are a variety of ways to do this, a simple web search will find all the different ways.

Also, it's much more convenient to just cut-and-paste directory trees rather than posting an image.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll go one step further and say that you should never use page-relative URLs.

There is a JSP FAQ entry on how to create server-relative URLs.
 
Mainak Goswami
Ranch Hand
Posts: 52
Eclipse IDE Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks David and Bear.
I will try your solution. 2 more queries for you:
i) Is the directory structure correct?
ii) Can you please provide a code snippet to give a more clear understanding of your explanation?
iii) Off track query: How do you copy paste the directory structure from Eclipse? I agree with your point that copy pasting directory structure is more convenient. But is there any way to do it easily?

Thanks in advance.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Get the directory structure from the command line, not the IDE.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm fast becoming convinced that IDEs are now the biggest impediment to actually learning something.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mainak Goswami wrote:Can you please provide a code snippet to give a more clear understanding of your explanation?

Did you read the FAQ entry? That's why there are FAQ entries -- so the same information doesn't have to be repeated again and again.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Did you read the FAQ entry?

I guess *that* question has to go into the meta-FAQ.
 
Mainak Goswami
Ranch Hand
Posts: 52
Eclipse IDE Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah ha!!! Yahoo...The code works...Thanks for the solution David and Bear & this is really very helpful.
I have gone through the FAQ and my code is working perfectly fine now.
Resource URL Problem
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad to hear you solved your problem!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic