Basic configuration of Jetty
Basic configuration of Jetty Similar to Tomcat, here we mainly introduce Jetty’s port settings and how to deploy web applications. Since Jetty is an embedded Web server, the setting method is quite special.
Jetty’s configuration file is placed in the etc path, and there are several configuration files in this path:
jetty.xml file.
jetty-jmx.xml file.
jetty-plus.xml file.
webdefault.xml file.
The webdefault.xm1 file is the default configuration file of the web application, which has nothing to do with the configuration of Jetty. This file usually does not need to be modified
The other three are Tomcat configuration files: jetty.xml file is the default configuration file; jetty-jmx.xml is the configuration file for starting JMX control; jetty-plus.xm1 is the configuration file for adding Jetty extended functions. Enter the following command when starting Jetty:
java-jar startup.jar |
< span style="color:rgb(85,85,85);font-family:'microsoft yahei';font-size:15px;background-color:rgb(255,255,255);">Start Jetty when the jetty.xm1 file is used by default , Which has the same effect as the following command:
java-jar startup.jar etc/jetty.xml |
java-jar startup.jaretc/jetty.xml etc/jetty-plus.xml |
Open the Jetty configuration file, the root element of the configuration file is Configure, and you will also see the following configuration
Set element.
Set: is equivalent to calling the setxx method.
Get: is equivalent to calling the getXxx method.
New: Create an instance of a certain class.
Arg: Pass in parameters for the method or constructor.
Array: Set an array.
Item: Set the -J page of the array or collection.
Call: Call a method.
Jetty is an embedded Web container, so its service corresponds to a Server instance, you can see the following fragments in the configuration file:
< /td> |
1. Configure Jetty service port
The various sub-elements in the Configure element are operations on the Server instance. Under the Configure element, there is the Set sub-element as shown in the following code. The name attribute of the Set sub-element is connectors. The effect is equivalent to calling the setConnectors method to set the provided port of the Web service. This method requires an array of Connectors, and the Array sub-elements contained in it are used to set the parameters of the method. The Item child element in the Array element is the data item of the array, and each Connector corresponds to a connection provider.
< Set name="Acceptors">l |
on top In the configuration snippet of, the first Connector is valid by default. This Connector is the connector of regular web services, and 8080 is the default port of Jetty.
The author modified the fragment as follows:
|
After modifying the example shown above, Jetty’s service port is 88860 This is also the port used by the author.
public class TestServlet extends HttpServletInitialContextic;//Servlet initialization method, which completes the initialization of Context public void init(ServletConfig config) throws ServletExceptionsuper.init(config);tryic=new InitialContext ();catch (Exception e){throw new ServletException(e);//service The method is the service method of Servlet public void service(HttpServletRequest request, HttpServletResponseresponse) throwsServletException, OException//Get JSP page output stream PrintStream out= newPr worker ntStream(response.getOutputStream()); try//output the binding value of wggle in the console System.out.println (ic.lookup("wiggle"));/I: output the binding value of woggle in the console Value System.out.println (ic.lookup("woggle"));//Get the bound data source DataSource ds = (DataSource)ic.lookup("jdbc/mydatasource");//Get the database connection through the data source Connectionconn = ds.getConnection();//Create Statement object Statement through database connection stmt=conn.createStatement();//Execute SQL query through Statement object and return ResultSet object ResultSet rs = stmt.executeQuer y("select* from news");//Traverse the record set while(rs.next())out.pr工ntl口(rs.getString(2));}catch(Exception e)e.printStackTrace(); Add the following fragment to the web.xml file: |
start Jetty, visit the Servlet, namely See the database access results
This article is from http://blog.csdn.net/u011225629/article/details /52316823
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 = 4575 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC