accessing CSS files in JSP

cant load/read/find CSS in JSP

Page 1 of 1

2 Replies - 14488 Views - Last Post: 07 June 2007 - 10:31 PM Rate Topic: -----

#1 larimore  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 18-March 07

accessing CSS files in JSP

Posted 07 June 2007 - 01:55 AM

Hello,

I hope someone can help. i have a css files that cant be found in my jsp file(s). i tried searching google,although there were a lot of similar question and reply, i just cant seem to make it work..here's the code..

this code appear in web.xml
<servlet>
<servlet-name>login_jsp</servlet-name>
<jsp-file>/WEB-INF/jsp/login.jsp</jsp-file>
</servlet>

<servlet-mapping>
<servlet-name>login_jsp</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping

i open the login.jsp pages in the browser by
http://localhost:8080/bellJSF/login

basically it cant find my css file(and also the image)
heres the code for login.jsp
<%@page pageEncoding="Windows-31J"%>
<html>
<head>
<title>Bellnet E-Bulletin System</title>
<link rel="stylesheet" type="text/css" href="<html:rewrite page='/css/main.css'/>">
</head>
<h1 align="center"><img src="<%=request.getContextPath()%>/WEB-INF/img/bellnet.gif"></h1>

<body class="background">
<form action="main" method="post">
<center>
<table>
<tr><th>ユーザID:</th><th><input type="text" name="userID"></th></tr><br><br>
<tr><th>パスワード:</th><th><input type="text" name="password"></th></tr>
</table>
<br><br><input type="submit" value="Login (ロッグイン)" size=200>
</center>
</form>
</body>
</html>

my folder structure looks like this
WEB-INF
img
css
main.css
jsp
login.jsp
classes

as you can see, i tried different approach in loading the image file and css file

anyway, thanks in advance

ill keep on dreaming..

Is This A Good Question/Topic? 0
  • +

Replies To: accessing CSS files in JSP

#2 salindor  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 46
  • View blog
  • Posts: 301
  • Joined: 10-November 06

Re: accessing CSS files in JSP

Posted 07 June 2007 - 03:51 PM

Sadly I think this may depend on what your using as an web application.

But looking at your snippet I see you have placed your gif under the WEB-INF and not your css. If I had to make a guess, I would say try moving your css under the WEB-INF. I believe (could be wrong) that there are some rules associated with the WEB-INF that you may be running into.

Anyways, sorry I couldn't be more helpful, but maybe that might.

Salindor
Was This Post Helpful? 0
  • +
  • -

#3 larimore  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 18-March 07

Re: accessing CSS files in JSP

Posted 07 June 2007 - 10:31 PM

Hi,
My bad, typo...actually here is how my folder look like..

WEB-INF
----img
>>img.gif
----jsp
>>login.jsp
----css
>>main.css

so, the css file is already inside the WEB-INF folder.
anyway i tried making a servlet for the main.css in web.xml
here is how the code look
<servlet>
<servlet-name>main_css</servlet-name>
<jsp-file>/WEB-INF/css/main.css</jsp-file>
</servlet>

<servlet-mapping>
<servlet-name>main_css</servlet-name>
<url-pattern>/style</url-pattern>
</servlet-mapping>

and when i call the css i write "style" in the href tag instead

<link rel="stylesheet" type="text/css" href="style">

i can now load the css files, but is this ok? i think i just "pretended" that my css file is a jsp file. im really just starting jsp
but i think calling css this way is really not the right way..and yup, i still cant upload my picture

anyway, thanks, as always..

This post has been edited by larimore: 07 June 2007 - 10:31 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1