小编wee*_*ger的帖子

如何在 Jetty 9(嵌入)中设置 HTTP-Session-Timeout?

我想在我的测试用例中使用嵌入的 Jetty 9 (v9.2.12.v20150709)。但我无法以编程方式更改 HTTP-Session-Timeout。

这个电话webapp.getSessionHandler().getSessionManager().setMaxInactiveInterval(timeoutInSeconds);好像打不通。

这是减少的代码段,它显示了我所做的:

import java.io.IOException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;

@SuppressWarnings("javadoc")
public class EmbeddedJetty
{

    @SuppressWarnings("serial")
    public static class TimeoutServlet extends HttpServlet
    {
        @Override
        protected void doGet(HttpServletRequest request,
                HttpServletResponse response) throws IOException
        {
            // return the value of the currently used HTTP-Session Timeout
            response.setContentType("text/html");
            response.setStatus(HttpServletResponse.SC_OK);
            response.getWriter().println("<h1>Timeout: " + request.getSession()
                    .getMaxInactiveInterval() + "</h1>");
        }
    }

    public static void main(String[] args) throws Exception
    {
        // the custom …
Run Code Online (Sandbox Code Playgroud)

java jetty embedded-jetty jetty-9

2
推荐指数
1
解决办法
7754
查看次数

标签 统计

embedded-jetty ×1

java ×1

jetty ×1

jetty-9 ×1