Avatar billede jadirir Nybegynder
30. november 2003 - 11:36 Der er 17 kommentarer

Servlet and CSS

Hi all
Can any one help me how to use Servlets with CSS? where should I place the css file?
I try it:
out.println("<link rel=\'StyleSheet\' type='text/css' ref=\'style.css\' />"); By putting same folder the class file and CSS file (in ..-webapps/myappl/WEBINF/classes), but it does help.
Please let me know if you can.
Thanks
Avatar billede arne_v Ekspert
30. november 2003 - 13:17 #1
It depends on the servlet mapping.

If the servelet are accessed as /appname/servletname  via a mapping
in web.xml, then you should put the css in webapps/appname.
Avatar billede jadirir Nybegynder
30. november 2003 - 13:21 #2
I did so, but does not work.
Avatar billede arne_v Ekspert
30. november 2003 - 13:25 #3
/appname/servletname call the servlet correct ?

the HTML contains ref='style.css' ?

styles.css is in webapps/appname ?
Avatar billede jadirir Nybegynder
30. november 2003 - 13:52 #4
Yes all three questions but does not work.
Avatar billede arne_v Ekspert
30. november 2003 - 13:55 #5
Can you see in the log-file what path is being requsted by the browser for
the CSS file ?
Avatar billede jadirir Nybegynder
30. november 2003 - 14:03 #6
Where and how can I see that?
Thanks you prompt reply
Avatar billede arne_v Ekspert
30. november 2003 - 14:18 #7
If you are using Tomcat, then you enable it in
server.xml and the log file will be logs/localhost_access.log
Avatar billede arne_v Ekspert
30. november 2003 - 14:24 #8
Do you by any chance have Apache or IIS in front ?
Avatar billede jadirir Nybegynder
30. november 2003 - 15:08 #9
By enabling the localhost_access.log Does not help.
The servlet generates the following HTML code:
<html>
<head>
<title>Login page</title>
<link rel='StyleSheet' type='text/css' ref='style.css' />
</head>
<body>
<table align='center'>
<form method='get' action='Manager'>
<tr><td>UserName:</td><td><input type='text' name='username' /></td></tr>
<tr><td>Password:</td><td><input type='password' name='password' /></td></tr>
<tr><td colspan='2' align='right'><input name='submit' type='submit' value='Login' /></td></tr>
</form>
</table>
</body>
</html>
But could use the format of the CSS file.
Thanks
Avatar billede arne_v Ekspert
30. november 2003 - 15:10 #10
Ofcourse enabling log did not help.

But what was written in lthe access log ?

First a request for you servlet - and then a request for what ?
Avatar billede jadirir Nybegynder
30. november 2003 - 15:20 #11
This is what I have in the file:
127.0.0.1 - - [30/Nov/2003:15:05:23 +0100] "GET /csproject/Login HTTP/1.1" 200 469
127.0.0.1 - - [30/Nov/2003:15:05:24 +0100] "GET /csproject/Manager?username=&password=&submit=Login HTTP/1.1" 200 1958
127.0.0.1 - - [30/Nov/2003:15:19:30 +0100] "GET /csproject/Manager?username=&password=&submit=Login HTTP/1.1" 200 1958
127.0.0.1 - - [30/Nov/2003:15:19:33 +0100] "GET /csproject/Manager?username=&password=&submit=Login HTTP/1.1" 200 1958
Avatar billede arne_v Ekspert
30. november 2003 - 15:29 #12
No request for the CSS ?

Which indicates that it is not aproblem with the location of the file.

Hm.
Avatar billede jadirir Nybegynder
04. december 2003 - 12:03 #13
Still I have a problem where to put the CSS file
Avatar billede arne_v Ekspert
04. december 2003 - 12:12 #14
If th elog file does not contain a request for the CSS file, then
that is actually not your problem.

The problem is why does the server not receive a request from the
browser.

[I still believe that my first comment was correct]
Avatar billede jadirir Nybegynder
04. december 2003 - 12:15 #15
So do you think, it will work (get access CSS file) if I use another server?
Avatar billede arne_v Ekspert
04. december 2003 - 12:37 #16
Do you have Apache or IIS in front of Tomcat ?
Avatar billede jadirir Nybegynder
04. december 2003 - 14:45 #17
Jakarta tomcat 5.0.6
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester