簡體   English   中英

Struts2,Guice和index.jsp

[英]Struts2, Guice and index.jsp

使用類似於從吉斯項目例如GuiceServletContextListener子類在這里 ,和web.xml 這里

我發現瀏覽根目錄(例如localhost:8080)時從未訪問過Webapp的index.jsp 考慮到web.xml的配置,這是正確的:

  <welcome-file-list>
    <welcome-file>index</welcome-file>
  </welcome-file-list>

(請參見下面的web.xml

您可能已經注意到index.jsp文件缺少后綴.jsp 這是因為Struts2文檔在此處建議將安全性約束添加到web.xml中。 如果添加了后綴或省略了歡迎文件列表,則安全約束將生效。

因此,我不得不以(看起來像)奇怪的方式配置Struts2才能使應用程序正常工作:

<action name=""/>

(請參閱下面的struts.xml

問題

Struts2配置是否正確? 還是應該以不同的方式配置Struts2? 如果是這樣,該怎么辦?

非常感謝任何幫助。

設定

  • Java 8
  • 雄貓9
  • 支撐桿2.5.20
  • 吉斯4.2.2

web.xml中

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">

  <display-name>PVS Web Application</display-name>

  <listener>
    <listener-class>org.veary.pvs.web.guice.GuiceListener</listener-class>
  </listener>  

  <filter>
    <filter-name>guice</filter-name>
    <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>guice</filter-name>
    <url-pattern>/*</url-pattern>
 </filter-mapping>

  <welcome-file-list>
    <welcome-file>index</welcome-file>
  </welcome-file-list>

  <security-constraint>
    <display-name>No direct JSP access</display-name>
    <web-resource-collection>
      <web-resource-name>No-JSP</web-resource-name>
      <url-pattern>*.jsp</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <role-name>no-users</role-name>
    </auth-constraint>
  </security-constraint>

  <security-role>
    <description>Don't assign users to this role</description>
    <role-name>no-users</role-name>
  </security-role>

</web-app>

在struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"https://struts.apache.org/dtds/struts-2.5.dtd">

<struts>

    <constant name="struts.devMode" value="true"/>
    <constant name="struts.ui.theme" value="simple" />

    <package name="pvs-base" namespace="/" extends="struts-default">
      <interceptors>
        <interceptor-stack name="pvsDefault">
          <interceptor-ref name="validationWorkflowStack"/>
        </interceptor-stack>
      </interceptors>
      <default-interceptor-ref name="pvsDefault" />
      <global-results>
        <result>/themes/default/layout.jsp</result>
      </global-results>
      <action name=""/>
    </package>

</struts>

答案也許比我想的要容易:

  • 修改web.xml以使用index.html而不是index.jsp

    <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list>

  • 在新的index.html中,使用以下命令:

    <META HTTP-EQUIV="Refresh" CONTENT="0;URL=index">

    要么

    <script>top.location='index';</script>

  • struts.xml中 ,更改為以下內容:

    <action name="index"/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM