Setting dirAllowed to false in Jetty 8.1.12

我是研究僧i 提交于 2019-12-06 14:59:55

The upgrade from Jetty 6 to Jetty 8 requires you to update your Jetty references.

To start with, you'll need to update all of your named classes. The project moved to the Eclipse Foundation 6 years ago, this resulted in a mandatory package name change from org.mortbay.jetty to org.eclipse.jetty

Then you'll want to update the various setters to be relevant to what you are attempting to do.

Would recommend that you grab a copy of the Jetty Distribution tarball (or zip) and check out the Jetty XML files that it comes with for some inspiration, while also referencing the Jetty 8 Javadocs for some details.

Note: Jetty 6 was EOL'd in 2010. Jetty 8 is EOL at the end of 2014, there will be no more updates to Jetty 8 after this year. Would highly encourage that you upgrade all the way to Jetty 9 now.

An temp workaround should be create a custom WebAppContext, it's not grace but works.

public class CustomWebAppContext  extends org.eclipse.jetty.webapp.WebAppContext{
  public void setInitParams(Map<String, String> values){
    Map<String, String> currectParams= getInitParams();
    if(currectParams==null){
        currectParams= new HashMap<String, String>();
    }
    for(Map.Entry<String,String> entry : values.entrySet()){
        currectParams.put(entry.getKey(), entry.getValue());
    }
}}

Then in xml :

      <bean class="CustomWebAppContext">
                                    <property name="contextPath" value="/fileServer" />
                                    <property name="resourceBase" value="ResourcePath" />
                                    <property name="initParams">
                                        <map> 
                                           <entry key="org.mortbay.jetty.servlet.Default.dirAllowed" value="false" />
                                        </map>
                                    </property>
                            </bean>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!