Frage

Ich folge diesem Beispiel, um Spring Up & Laufen zu erhalten: http://static.springource.org/docs/spring-mvc-step-by-step/part2.html

Was sie tun, ist, alle .jsp-Dateien im Web-Inf zu verschieben, um Benutzer zu verhindern, dass sie direkt auf sie zugreifen ... so weit so gut. Das Servlet verfügt jedoch über eine willkommene Seite von index.jsp, und wenn dies in der Web-Inf-Dire verschoben wird, bekomme ich Fehler. Ich kann nicht feststellen, ob Tomcat 6 zulassen, dass sich die Begrüßungsseite innerhalb des Web-Infs befinden oder nicht.

War es hilfreich?

Lösung

Nichts in Web-Inf kann direkt zugegriffen werden, muss jedoch zuerst etwas anderes (normalerweise ein Servlet) durchlaufen, das dann die Anfrage intern an die Web-Inf-Ressource weiterleitet.

Andere Tipps

Ich versuche das gleiche Tutorial. Das Tutorial sagt dies nicht, aber ich habe den Wert in meinem web.xml von "index.jsp" auf "/web-inf/jsp/index.jsp" geändert.

Ich verwende eine solche Technik (die für Servlet -API> = 2.4 funktioniert):

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
    <url-pattern>/index.htm</url-pattern>    <<==  *1*
</servlet-mapping>
<welcome-file-list>
    <welcome-file>index.htm</welcome-file>   <<== *2*
</welcome-file-list>

Sie brauchen also nicht mehr redirect.jsp mit:

<% response.sendRedirect("/myproject/MyAction.action"); %>

in nichtWEB-INF Verzeichnis!!

Hier zwei Blogs mit gleicher Technik:

AKTUALISIEREN Aus SRV.9.10 Welcome Files Abschnitt von Servlet API 2.4 Dokumentation^

The purpose of this mechanism is to allow the deployer to specify an ordered
list of partial URIs for the container to use for appending to URIs when there is a
request for a URI that corresponds to a directory entry in the WAR not mapped to
a Web component. This kind of request is known as a valid partial request.

The use for this facility is made clear by the following common example: A
welcome file of `index.html' can be defined so that a request to a URL like
host:port/webapp/directory/, where `directory' is an entry in the WAR that is
not mapped to a servlet or JSP page, is returned to the client as `host:port/
webapp/directory/index.html'.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top