@WebServlet(name = "registration servlet", urlPatterns = "/register")
public class Register extends HttpServlet{
PrintWriter output;
private final static int EMPTY = 0;
private static int byteContainer = 0;
private static int lines = 0;
private static String charContainer = "";
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
output = resp.getWriter();
output.print("The Do Get METHOD");
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
output = resp.getWriter();
ServletInputStream servletInputStream = req.getInputStream();
if(servletInputStream.isReady()){
byte [] bytes = new byte[4096];
while((byteContainer = servletInputStream.read()) != -1){
bytes [lines] = (byte)byteContainer;
lines++;
if((servletInputStream.read()) == -1){
char [] chars = new char[4096];
for(int i = 0, k = 0 ; i < lines; i++, k++){
chars[i] = (char) bytes [k];
charContainer += chars[i];
}
}
}
}
lines = EMPTY;
output.print(charContainer);
servletInputStream.close();
Запрос Ajax:
$("#register-button").click(function () {
var user = {
firstName:$("#first-name").val(),
lastName:$("#last-name").val(),
nickName:$("#nick_name").val(),
email:$("#email_").val(),
password:$("#password_").val(),
customerType:$("#cust-type").val()
}
console.log(user);
var JSONString = JSON.stringify(user);
var JSONObject = JSON.parse(JSONString);
console.log(JSONObject);
var url = "http://localhost:8080/CouponProject/register";
$.ajax({
url:url,
method:"post",
data:JSONObject,
contentType:"application/json",
error:function (message) {
console.log(message+" In the error function!")
},
success:function (data) {
console.log(data);
},
headers:
{
"Accept":"application/json",
"Accept-Language":"en",
"Cache-Control":"max-age=3600"
}
});
});
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1100) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:687) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)
24-Sep-2016 11:45:27.632 SEVERE [http-nio-8080-exec-6] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [registration servlet] in context with path [/CouponProject] threw exception java.lang.IllegalStateException: Not available in non blocking mode at org.apache.catalina.connector.InputBuffer.isReady(InputBuffer.java:297) at org.apache.catalina.connector.CoyoteInputStream.isReady(CoyoteInputStream.java:242) at coupon.registration.Register.doPost(Register.java:37) at javax.servlet.http.HttpServlet.service(HttpServlet.java:648) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1100) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:687) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)
При запросе на данный код сервлета.. Получаю такую ошибку.
Знаю что это ошибка связанна с сервером , но не могу понять что это за ошибка и почему она происходит в моём случаи ?