问题描述:

I'm using Jetty 8 as embedded server in a project. Everything works as expected, except multipart/form-data requests.

My servlet which has to process the multipart/form-data requests works fine, - I've tested it with the RunJettyRun plugin of eclipse. That's why the embedded server code must be the guilty part.

My code follows the jetty examples like this. I've searching the internet since 2 days, but didn't find out how to config jetty.

Every hint is welcome,

kind regards,

Sea

网友答案:

Things can be so simple. You just have to set the MultipartConfig to your ServletHolder. For example:

ServletHolder sh = new ServletHolder(YourServlet.class);
sh.getRegistration().setMultipartConfig(new MultipartConfigElement("yourTempLocation", 1048576, 1048576, 262144));

Just annotate YourServlet with @MultipartConfig and you have full access to the multipart/form-data.

网友答案:

You can either set multipart support through by adding the required class to the server directly,

org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
    classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
    classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");

or adding the required configurations to your web app context, as in:

WebAppContext myWebAppContext= new WebAppContext();     
myWebAppContext.setConfigurations(new Configuration[] { new AnnotationConfiguration(), new WebInfConfiguration(),
            new WebXmlConfiguration(), new FragmentConfiguration(), new EnvConfiguration(), new PlusConfiguration(),
            new JettyWebXmlConfiguration() });
相关阅读:
Top