Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

sendRedirect and CSS!  RSS feed

 
David Cox
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

I am experiancing strange problom.

I have a Filter which is redirects the user request to a perticular page according to some conditions.

I get everything right with sendRedirect,but the resulting page does'nt coming with CSS styles.

For example, if i redirects to Register.jsp,the actual page(Register.jsp) look nice with CSS.But when the page displays as the effect of sendRedirect,the page comes as only HTML. CSS styles are not including.

Why this behavior?.

Thanks,
DC
[ April 26, 2005: Message edited by: Bear Bibeault ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at your browser's address window.

What is the difference in the URL when you hit it directly and when you come to it by the way of a re-direct?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most likely you are using a page-relative reference to the CSS file that is not resolving correctly.
 
David Cox
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
Look at your browser's address window.

What is the difference in the URL when you hit it directly and when you come to it by the way of a re-direct?


SAME..No difference at all,

Originally posted by Bear Bibeault:
Most likely you are using a page-relative reference to the CSS file that is not resolving correctly.


Yes..i dont add CSS class statements in evry HTML tags. But only use,

<LINK href="theme/newcss.css" rel="stylesheet" type="text/css">

So how can i resolve this issue?.

Thanks,
DC
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<link href="/contextname/theme/newcss.css" rel="stylesheet" type="text/css"/>

Where contextname is the name of the app context and the theme folder is at the root of the web app base. (If not, insert the appropriate folder hierarchy).

To obtain the context name programatically you can use request.getContextPath() in JSP 1.x or ${pageContext.request.contextPath} in JSP 2.0.
 
David Cox
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
<link href="/contextname/theme/newcss.css" rel="stylesheet" type="text/css"/>

Where contextname is the name of the app context and the theme folder is at the root of the web app base. (If not, insert the appropriate folder hierarchy).

To obtain the context name programatically you can use request.getContextPath() in JSP 1.x or ${pageContext.request.contextPath} in JSP 2.0.


Hi Bear,

I put the following in my code, But still the result is same!.



After inserting context path, when i call Register.jsp(for example) without sendRedirect(By hitting URL in browser) the page does'nt get CSS effect.

But without inserting context path, calling Register.jsp from browser gives CSS effect.But with sendRedirect does'nt give CSS style.

So the problom is very related to sendRedirect. Any ideas?.

Thanks,
DC
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the location of the two pages and the css sheet?
Are both JSPs in the same context?

Post the paths on the server and the URLs used to reach both.
 
David Cox
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
Can you post the location of the two pages and the css sheet?
Are both JSPs in the same context?

Post the paths on the server and the URLs used to reach both.



myWebApp/ShowHomePage.jsp
myWebApp/Register.jsp
myWebApp/theme/newcss.css

http://localhost:8880/myWebApp/ShowHomePage.jsp
http://localhost:8880/myWebApp/Register.jsp

They all in same context. When i hit

http://localhost:8880/myWebApp/Register.jsp without using the Filter(Filter using sendRedirect) in browser, it shows CSS effect.

But when Filter enabled, if i try to access http://localhost:8880/myWebApp/ShowHomePage.jsp, the Filter redirects the browser to http://localhost:8880/myWebApp/Register.jsp using sendRedirect. the Register.jsp is displaying without CSS!.

It seems strange and it become stranger,

i use,



in Filter class,the results are,

/scripts/global.js
/scripts/login_views.jsp
/theme/newcss.css
/ShowHomePage.jsp

STRANGE!!!.

i never HIT http://localhost:8880/myWebApp/scripts/global.js in my browser!!.sendRedirect sends these URI's to the server!!.

I took care to add a return statement after sendRedirect call.

What you thinks?

Thanks,
DC
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post the code snippet.
 
David Cox
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


If excludetList(Hashtable) contain the path of the request(request.getServletPath()) if block will be executed, otherwise else block will be executed.

I dont have problom here. The if and else blocks and Filter works fine, Only problom is redirected Page does'nt show CSS effect.

What you think?.

Thanks,
DC
[ April 27, 2005: Message edited by: David Cox ]
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. After getting that page without CSS, just refresh it using browser refresh button and then see whether it appears with CSS or not?
 
David Cox
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Adeel Ansari:
Ok. After getting that page without CSS, just refresh it using browser refresh button and then see whether it appears with CSS or not?


It's all same with refresh.

DC
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you performed the basic debugging step of doing a View Source of the page when it is misbehaving to see if the HTML is formatted correctly? Have you done a side-by-side comparison of the HTML when it appears correctly and when it does not?

This step could very well tell you where the problem lies.
 
David Cox
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
Have you performed the basic debugging step of doing a View Source of the page when it is misbehaving to see if the HTML is formatted correctly? Have you done a side-by-side comparison of the HTML when it appears correctly and when it does not?

This step could very well tell you where the problem lies.


I'll do that and tell you the result.

Thanks,
DC
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!