wood burning stoves 2.0*
The moose likes JSP and the fly likes JSP context problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP context problem" Watch "JSP context problem" New topic
Author

JSP context problem

Mainak Goswami
Ranch Hand

Joined: May 21, 2006
Posts: 50

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?


------------------------------------
Mainak
idiotechie
------------------------------------
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Sep 29, 2008
Posts: 12617

Confusingly, you do not actually show the JSP code that doesn't work.
Mainak Goswami
Ranch Hand

Joined: May 21, 2006
Posts: 50





[Thumbnail for Folder_Structure.jpg]

Mainak Goswami
Ranch Hand

Joined: May 21, 2006
Posts: 50

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

Joined: Jan 10, 2002
Posts: 60992
    
  65

Please do not quote your own text.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jan 10, 2002
Posts: 60992
    
  65

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

Joined: May 21, 2006
Posts: 50

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

Joined: Sep 29, 2008
Posts: 12617

Get the directory structure from the command line, not the IDE.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

I'm fast becoming convinced that IDEs are now the biggest impediment to actually learning something.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

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

Joined: Sep 29, 2008
Posts: 12617

Bear Bibeault wrote:Did you read the FAQ entry?

I guess *that* question has to go into the meta-FAQ.
Mainak Goswami
Ranch Hand

Joined: May 21, 2006
Posts: 50

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

Joined: Sep 29, 2008
Posts: 12617

Glad to hear you solved your problem!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP context problem