File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Unable to load CSS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Unable to load CSS" Watch "Unable to load CSS" New topic
Author

Unable to load CSS

an bo
Greenhorn

Joined: Mar 24, 2009
Posts: 5
Hi, i m having some problem with my struts application. I am tring do a forward from action class to some jsp page. When i do so the jsp loads but without the CSS formatting . But when i give the complete path of that jsp, everything loads properly. Please help.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9307
    
  17

Hi anup, welcome to javaranch.

Can you give a little code for your action, the struts configuration and the locations of your JSP and CSS files for us to be able to solve your problem better...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
an bo
Greenhorn

Joined: Mar 24, 2009
Posts: 5
Hi Ankit,

Here's the code and all....

Code in Action Class(UserRegAction.java):
return mapping.findForward("success");

Struts-config:
<action input="/pages/loginform.jsp" name="UserRegForm" path="/register"
scope="request" type="com.blog.controller.action.UserRegAction">
<forward name="success" path="/pages/welcomelogin.jsp"/>
<forward name="failure" path="/pages/failure.jsp"/>
</action>


Code in Welcomepage.jsp:
<link rel="stylesheet" href="../assets/css/style.css" type="text/css" media="all" />

Locations:
loginform.jsp - Webcontent/pages/loginform.jsp
Welcomepage.jsp - Webcontent/pages/Welcomepage.jsp
style.scc - Webcontent/assets/css/style.css

Thanks
-Anup
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Just for test purpose, do

Just replace the "Application_Name" with the context OR name of your web app, and re run.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
an bo
Greenhorn

Joined: Mar 24, 2009
Posts: 5
@Sagar : No Success.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

You have to play around with it,
Try
an bo
Greenhorn

Joined: Mar 24, 2009
Posts: 5
Hey Sagar,
Following worked.

<link rel="stylesheet" href="../App/assets/css/style.css" type="text/css" media="all" />

Thanks a bunch, Sir.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Welcome, and please don't called "Sir"
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

In general when creating links inside an app you'll want to use the <html:rewrite> (Struts 1), <s:url> (Struts 2), or <c:url> (JSTL) to create the links. This way you decouple your JSP from the deployment environment.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to load CSS