GeeCON Prague 2014*
The moose likes Struts and the fly likes Struts help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts help" Watch "Struts help" New topic
Author

Struts help

Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
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

<action-mappings>

<action name="update" path="/update" scope="request"
type="com.test.testweb.actions.UpdateAction">

<forward name="success" path="/jsp/Test1.jsp">

</forward>

</action>

</action-mappings>
Here, when I added the action mapping, I am forwarding to the same
page, test1.jsp after a success. ie, my form is getting submitted and
I
am
coming to the same page.

But when the same page gets displayed again, the images are not
getting
displayed and its not recognising the css file.
My console gives the following errors:

[3/19/04 9:16:40:408 CST] 154a763c OSEListenerDi E PLGN0021E: Servlet
Request Processor Exception: Virtual Host/WebGroup Not Found : The
web
group /images/logo.gif has not been defined

Why is this happening ?

Do I need to add anything so that the images and css files are
recognised from an action link ?

Thanks
Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
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.


Anthony W.<br />MCP, SCJP 1.4, SCJD, SCWCD 1.3, SCWCD 1.4, SCBCD
brad balmer
Ranch Hand

Joined: Mar 08, 2004
Posts: 57
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.
Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
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
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4474
    
    6

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.


Junilu - [How to Ask Questions] [How to Answer Questions]
poornima balagopal
Ranch Hand

Joined: Dec 02, 2003
Posts: 83
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
Ace Frehley
Greenhorn

Joined: Sep 03, 2004
Posts: 1
Thanks Poornima. Your approach works great.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts help