我想实现的概念ConnectionPooling中Oracle使用Jetty的服务器.我在教程中看到了以下内容.如果我使用Tomcat服务器部署它,它Jetty似乎工作,但似乎给了我一个不寻常的error.详情如下 -
我有一个名为TestServlet.java-
import java.io.IOException;
import java.sql.*;
import javax.naming.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import javax.sql.DataSource;
@SuppressWarnings("serial")
@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
public TestServlet() throws ServletException{
System.out.println("Constructor");
init();
}
public DataSource dataSource;
private Connection con;
private Statement statement;
public void init() throws ServletException {
System.out.println("inside init method");
try {
// Get DataSource
Context initContext = new InitialContext();
System.out.println("Before envcontext");
Context envContext = (Context)initContext.lookup("java:comp/env"); …Run Code Online (Sandbox Code Playgroud) 我正在开发一个RESTFul web service项目POJO如下:
@XmlRootElement
public class Input {
//variable declarations
public Input(){
//default constructor
}
//constructor no 1
public Input(String LR, double ECH,double CSH,String APP) {
this.LR = LR;
this.ECH = ECH;
this.CSH = CSH;
this.APP = APP;
}
//constructor no 2
public Input(String LR, double ECH,double CSH,String APP,...) {
this.LR = LR;
this.ECH = ECH;
this.CSH = CSH;
this.APP = APP;
//constructor of all other parameters including these
}
//getters and setters method below.
} …Run Code Online (Sandbox Code Playgroud) 我JSP包含此form标签:
<form action="MyServlet" method="post">
Fname:<input type="text" id="fname" placeholder="type first name"/>
<input type="submit" value="ok"/>
</form>
Run Code Online (Sandbox Code Playgroud)
我的servlet是:
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.cad.database.DatabaseClass;
import com.cad.example.service.InputService;
public class Input extends HttpServlet {
private static final long serialVersionUID = 1L;
public Input() {
super();
// TODO Auto-generated constructor stub
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String fname = request.getParameterById("fname");
System.out.println("My name "+fname);
}
}
Run Code Online (Sandbox Code Playgroud)