package cn.cstnet;
import java.io.IOException;
import javax.servlet.ServletException;< br />import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
< br />public class testJetty {
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/HelloJetty" );
server.setHandler(context);
context.addServlet(new ServletHolder(new HelloServlet()), "/*");
server. start();
}
public static class HelloServlet extends HttpServlet {
private static final long serialVersionUID = -6154475799000019575L;
private static final String greeting = "Hello Jetty";
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
response.setContentType("text/html");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println(greeting );
}
}
}
Access URL:
http://locahost:8080/HelloJetty
Output:
HelloJetty
package cn.cstnet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
impo rt javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
public class testJetty {
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/HelloJetty");
server.setHandler(context);
context.addServlet( new ServletHolder(new HelloServlet()), "/*");
server.start();
}
public static class HelloServlet extends HttpServlet {
private static final long serialVersionUID = -6154475799000019575L;
private static final String greeting = "Hello J etty";
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
response.setContentType("text/html");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println(greeting);
}
}
}
Access URL:
http://locahost:8080/HelloJetty
Output:
HelloJetty
WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4534 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC