This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi, I am using struts with WSAD for creating my web application. I have a jsp page which intern calls a css file and displays images also. when I call my jsp: , test1.jsp, the page displays fine and I can see the i,ages and the css file also takes effect.
Now, I added an action mapping, updateAction in my struts config file
I think that your problem is occurring because you wrote your jsp page to be able to find your images and css file relative to the url that the jsp is accessed from. However, when a request is forwarded from an action, the url does not change to indicate a move to the jsp page. Try using the <html:base/> tag to fix this. Just insert this tag in the head section of your html. This tag will make it so that the jsp page tries to find the images and css relative to the same location, regardless or the url.
In addition to the <html:base/> tag, make sure that you reference your images/css using a neutral location, meaning: <LINK rel="stylesheet" type="text/css" href="<html:rewrite page='/theme/Master.css'/>"> Using html:rewrite instead of hardcoding the location of the css/images.
Joined: Jul 31, 2001
Thank you for the quick responses. Yes, My directory structure is like this testweb javasource webcontent css jsp images js And this is how I refer to a css file <link rel="stylesheet" type="text/css" href="../css/mine.css" /> using <html:base/> tag helped. Thanks again
Originally posted by Shreya Menon: And this is how I refer to a css file <link rel="stylesheet" type="text/css" href="../css/mine.css" /> using <html:base/> tag helped.
----- If you're sure your structure will never change, then that's fine. If not, you'd be wise to follow Brad's advice about using html:rewrite with the css href. Using a relative path is just inviting trouble to come back and bite you in the future. With rewrite, you are at least sure what the path is relative to. Just my humble $0.02 though.
Hi, I am using context path in my JSPs to refer to the images and css files as follows <link rel="StyleSheet" type="text/css" href="<%=request.getContextPath()%>/cssStyle/menu.css"> try this way it will pick up the files and images when the page is getting loaded or reloaded