B4J Question Change a jetty style file in a server ?

derez

Expert
Licensed User
Longtime User
Hi
A server for downloading my files from my pc.
The first page is login page, if password ok it uses a handler to make the list of files in the public directory.
The style until now is controlled by index.css and the code in the handler.
Clicking a dir from the list I get the subfolder with the list of files/dirs inside. The style here is by a jetty-dir.css which I can't control. I see it when I look at page source.
I looked for it inside jetty-b4j.jar but it is not there.
Any idea how to modify the style ? This is how it looks:
upload_2017-5-10_12-38-45.png


This is the page source:
<HTML><HEAD><LINK HREF="jetty-dir.css" REL="stylesheet" TYPE="text/css"/><TITLE>Directory: /Android/</TITLE></HEAD><BODY>
<H1>Directory: /Android/</H1>
<TABLE BORDER=0>
<TR><TD><A HREF="/Android/../">Parent Directory</A></TD><TD></TD><TD></TD></TR>
<TR><TD><A HREF="/Android/Demo/">Demo/&nbsp;</A></TD><TD ALIGN=right>0 bytes&nbsp;</TD><TD>Jun 25, 2015 11:24:21 AM</TD></TR>
<TR><TD><A HREF="/Android/Games/">Games/&nbsp;</A></TD><TD ALIGN=right>4096 bytes&nbsp;</TD><TD>Mar 2, 2017 11:07:20 PM</TD></TR>
<TR><TD><A HREF="/Android/Utilities/">Utilities/&nbsp;</A></TD><TD ALIGN=right>16384 bytes&nbsp;</TD><TD>Apr 30, 2017 9:57:36 PM</TD></TR></TABLE>
</BODY></HTML>

This is the jetty-dir.css file:
body
{
background-color: #FFFFFF;
margin: 10px;
padding: 5px;
}

h1
{
text-shadow: #000000 -1px -1px 1px;
color: #FC390E;
font-weight: bold;
}

a
{
color: #7036be;
font-weight: bold;
font-style: normal;
text-decoration: none;
font-size:inherit;
}

td
{
font-style: italic;
padding: 2px 15px 2px 0px;
}

See also this link https://www.eclipse.org/jetty/documentation/9.4.x/resource-handler.html
 

Daestrum

Expert
Licensed User
Longtime User
I just looked in my jetty_b4j.jar and jetty-dir.css is in the root folder in the jar.
 
Upvote 0

derez

Expert
Licensed User
Longtime User
I have extracted it by RAR and by 7-zip.

upload_2017-5-10_17-59-11.png



upload_2017-5-10_17-57-40.png


What about the fact that I can delete this jar file and the program still runs ?
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Your file is smaller than the one I have.

Mine is 2477KB
 
Upvote 0

derez

Expert
Licensed User
Longtime User
In the installation directory of B4J (libraries) it is 2477 as well.
The file in the application public folder is an old one. If it is not necessary for then it is taken from the b4j libraries. I'll check changing it now.

Edit: After changing the css file in the jar file nothing changes.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Extract jetty-dir.css from the jar and put it in the www folder. Modify it as needed.
2. Add a filter class with this code:
B4X:
Public Sub Filter(req As ServletRequest, resp As ServletResponse) As Boolean
   If req.RequestURI.EndsWith("jetty-dir.css") And req.RequestURI <> "/jetty-dir.css" Then
     resp.SendRedirect("/jetty-dir.css")
     Return False
   End If
   Return True
End Sub
3. Register the filter class:
B4X:
srvr.AddFilter("/*", "DirCss", False)
 
Upvote 0

derez

Expert
Licensed User
Longtime User
I have modified it to
B4X:
Public Sub Filter(req As ServletRequest, resp As ServletResponse) As Boolean
    Log( req)
    If req.RequestURI.Contains(".") = False And req.RequestURI <> "/download" Then
        resp.SendRedirect("/jetty-dir.css")
        Return False
    End If
    Return True
End Sub
so that it enters the if at the right event but the line resp.SendRedirect("/jetty-dir.css") just displays the original css file's content ...I need to target the file that creates the directory's content and tell it to use the modifed css file:
B4X:
<HTML><HEAD><LINK HREF="jetty-dir.css" REL="stylesheet" TYPE="text/css"/><TITLE>Directory: /Android/</TITLE></HEAD><BODY>
<H1>Directory: /Android/</H1>
<TABLE BORDER=0>
<TR><TD><A HREF="/Android/../">Parent Directory</A></TD><TD></TD><TD></TD></TR>

<TR><TD><A HREF="/Android/Demo/">Demo/&nbsp;</A></TD><TD ALIGN=right>0 bytes&nbsp;</TD><TD>Apr 6, 2016 8:16:33 AM</TD></TR>
<TR><TD><A HREF="/Android/Games/">Games/&nbsp;</A></TD><TD ALIGN=right>4096 bytes&nbsp;</TD><TD>Apr 6, 2016 8:16:38 AM</TD></TR>
<TR><TD><A HREF="/Android/Utilities/">Utilities/&nbsp;</A></TD><TD ALIGN=right>16384 bytes&nbsp;</TD><TD>Apr 6, 2016 8:17:04 AM</TD></TR></TABLE>
</BODY></HTML>

But - forget it, I'll write a dedicated handler for the subfolders case and use my own css file.
 
Upvote 0
Top