Avatar billede fredand Forsker
02. januar 2006 - 20:57 Der er 16 kommentarer og
3 løsninger

How to set Welcome file with struts tiles?

Hello!

I use Struts and in the web.xml it is possible to set the welcome file like:

  <!-- The Usual Welcome File List -->
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>

Now I would like to set the welcome file pointing to a struts tile looking like:

    <definition name="tiles.index" page="/tiles/template.jsp">
      <put name="header" value="/tiles/header.html" />
      <put name="body" value="/tiles/index.jsp" />
      <put name="footer" value="/tiles/footer.html" />
    </definition>

I have tried to this:
  <!-- The Usual Welcome File List -->
  <welcome-file-list>
    <welcome-file>/tiles/index.do</welcome-file>
  </welcome-file-list>

But I do not get it to work, so if you guys got any ideas please let me know!

Best regards
Fredrik
Avatar billede fsconsult.dk Nybegynder
03. januar 2006 - 05:25 #1
First of all, you can't!    It is not struts related, but the welcome file HAS to be a "real" file ..  i.e. html or jsp, it can't be a servlet.

The typical solution is to use index.jsp as the welcome file as:
----------------------------------------------------------------
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<logic:redirect forward="welcome"/>
----------------------------------------------------------------

and then define "welcome" in your gloabl-forward section in struts-config.xml
Avatar billede arne_v Ekspert
03. januar 2006 - 17:18 #2
If the container follows servlet spec 2.4 (or newer) then it can be a servlet.
Avatar billede fsconsult.dk Nybegynder
03. januar 2006 - 17:57 #3
nice to know!  ;-)
Avatar billede fredand Forsker
04. januar 2006 - 10:02 #4
Hello!

I think I got it right, but could I elminate the start.jsp in the following example and just go to tiles.index directly???

Now I did like I guess you said:

web.xml:
  <!-- The Usual Welcome File List -->
  <welcome-file-list>
    <welcome-file>pages/start.jsp</welcome-file>
  </welcome-file-list>

start.jsp:
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<logic:redirect forward="start"/>

struts-config.xml: (global-forwards)
    <global-forwards>
        <!-- Default forward to "Welcome" action -->
        <!-- Demonstrates using index.jsp to forward -->
        <forward
            name="start"
            path="/start.do"/>
    </global-forwards>

struts-config.xml: (action-mappings)
    <action path="/start" forward="tiles.index"/>

tiles-defs.xml
    <definition name="tiles.index" page="/tiles/template.jsp">
      <put name="header" value="/tiles/header.html" />
      <put name="body" value="/tiles/index.jsp" />
      <put name="footer" value="/tiles/footer.html" />
    </definition>

Do you see if it is possible to eliminate the start.jsp and map the welcome-file-list direct to tiles.index???

Best regards
Fredrik
Avatar billede fsconsult.dk Nybegynder
04. januar 2006 - 11:05 #5
as Arne wrote, ONLY with servlet spec 2.4 (or newer)
Avatar billede arne_v Ekspert
04. januar 2006 - 11:07 #6
which probably requires:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
      ...
</web-app>
Avatar billede fredand Forsker
04. januar 2006 - 11:33 #7
Hello!

Hmm okey, let see. If I'm right my orion 2.0.5 should support servlet spec 2.4.

But if I try:
web.xml:
  <!-- The Usual Welcome File List -->
  <welcome-file-list>
    <welcome-file>start.do</welcome-file>
  </welcome-file-list>


struts-config.xml: (global-forwards)
    <global-forwards>
        <!-- Default forward to "Welcome" action -->
        <!-- Demonstrates using index.jsp to forward -->
        <forward
            name="start"
            path="/start.do"/>
    </global-forwards>

struts-config.xml: (action-mappings)
    <action path="/start" forward="tiles.index"/>

...It does not work
do you guys see anything silly about the above?

To arne do you mean that
Avatar billede fredand Forsker
04. januar 2006 - 11:34 #8
...sorry arne to quick on the sen button...
To arne: do you mean that the xmlns:... should be added to the web-app tag in the web.xml file?

Best regards
Fredrik
Avatar billede arne_v Ekspert
04. januar 2006 - 11:44 #9
yes
Avatar billede arne_v Ekspert
04. januar 2006 - 11:45 #10
I do not know Orion but at least Tomcat treats the web app based on the
servlet spec version in the web.xml
Avatar billede fredand Forsker
04. januar 2006 - 12:27 #11
Hello!

Thanks for all help, but it looks like my orion does not responds well to the xmlns-attrubute.

I received:
Error loading web-app 'website' at D:\Fredrik\orion_kurser\applications\website\website: Unknown assembly root-tag attribute: xmlns
when i added this in my web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
  PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
  "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
  <display-name>Struts Blank Application</display-name>

Best regards
Fredrik
Avatar billede arne_v Ekspert
04. januar 2006 - 12:32 #12
DTD 2.2 and Schema 2.4 in same web.xml does not sound rigth
Avatar billede fredand Forsker
04. januar 2006 - 12:50 #13
Hello!
You got a point there!!

Hmm, but I tried a long shot changing the path for DTD to:
http://java.sun.com/j2ee/dtds/web-app_2_4.dtd
but it does not look like to be a valid path (page not found).

Best regards
Fredrik
Avatar billede arne_v Ekspert
04. januar 2006 - 13:08 #14
no - they swicthed from DTD to Schema

try just the schema as I outlined it
Avatar billede fredand Forsker
04. januar 2006 - 13:25 #15
Hello!

I tried:
<?xml version="1.0" encoding="ISO-8859-1"?>

<!--<!DOCTYPE web-app
  PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
  "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">-->

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
  <!--<web-app>-->

But I got the same error saying:
Unknown assembly root-tag attribute: xmlns

Best regards
Fredrik
Avatar billede arne_v Ekspert
05. januar 2006 - 10:45 #16
either Orion does not support that

or it is not allowed with whitespace & comments there
Avatar billede fredand Forsker
05. januar 2006 - 16:26 #17
Thanks for all help!

I have done no progress but I do think you both should split the points, so please give me an answer arne so I can reward you as well.

Best regards
Fredrik
Avatar billede fsconsult.dk Nybegynder
05. januar 2006 - 16:27 #18
:-)
Avatar billede arne_v Ekspert
05. januar 2006 - 17:52 #19
.
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