Hello Everyone,

I used to have a post function that works but it suddenly says: aborted when I run firebug on it and I dont know how I can fix it.

I am using servlets in a netbeans IDE and would like to know how to fix it. Once it says 500 internal error and once it says aborted, what can i do?

Recommended Answers

All 19 Replies

500 error means the problem occurs from your server side, not the browser or script code. Verify your server side code that it does not contain any error (when compile & run). There may be a certain input type that cause the exception in your server side code, and your code did not handle the exception properly.

Thank you for your reply.

SO, it has something to do with my java code. What about when it says aborted?

500 error means the problem occurs from your server side, not the browser or script code. Verify your server side code that it does not contain any error (when compile & run). There may be a certain input type that cause the exception in your server side code, and your code did not handle the exception properly.

Firebug may receive duplicate HTTP responses from the server, so it discards those responses but still reports them out to its debugging console.

so if I send a number as a post request, in the server part of the code, should it be Integer. parseInt(request.getParameter('the thing I sent');

it seems to be giving me an error in the java console about the parseInt

You should not attempt to parseInt from the param you get right away. The reason is that your Intger.parseInt() will automatically fail if the param value is in an incorrect format. Then it will throw NumberFormatException (I think) which cause the 500 error back to the client if you do not handle it properly. You should read the param in as String first. Then check if it is OK to parse. If it is not, either reject and return or attempt to work with it (I prefer the first way). You have to handle as much possible exception as you can on your server. If you do not want to handle it, reject and throw it back to the client (display error message or some thing).

Thank you Taywin, you have explained exactly what seems to be my problem.

But, I dont want to reject the parameter. Should I save the number as a string first, then parse it,

Please show me any examples of solutions.

Thank you so much,

You should not attempt to parseInt from the param you get right away. The reason is that your Intger.parseInt() will automatically fail if the param value is in an incorrect format. Then it will throw NumberFormatException (I think) which cause the 500 error back to the client if you do not handle it properly. You should read the param in as String first. Then check if it is OK to parse. If it is not, either reject and return or attempt to work with it (I prefer the first way). You have to handle as much possible exception as you can on your server. If you do not want to handle it, reject and throw it back to the client (display error message or some thing).

Yes, you should retrieve the parameter to a String first. If you want to sanitize it for an integer, what you need to do is to come up with a default value for what is coming in.

String expectedIntString = request.getParameter('the thing I sent');
int choice = 0;
// The regex pattern returns true for a string which may or may not start
// with + or - sign but must have all digit numbers until the end.
if (expectedIntString.match("^[-|+]?\\d+$")) {  // correct format
  choice = Integer.parseInt(expectedIntString);
}
// do nothing for else because choice has default value as 0

By the way, this is not a Java forum :( It is a JavaScript forum. :P

Taywin,

Thank you, I am using javascript ajax, this is whyI have posted my question here.
in my javascript, I have a post function
var x= numberSent
sendNumber(numberSent)
your telling me that x should be a string first?, Can I send it as a number without the need to parse it or anything, why should server side be so strict?
so, should numberSent be just like the way you wrote to me in your previous reply

Yes, you should retrieve the parameter to a String first. If you want to sanitize it for an integer, what you need to do is to come up with a default value for what is coming in.

String expectedIntString = request.getParameter('the thing I sent');
int choice = 0;
// The regex pattern returns true for a string which may or may not start
// with + or - sign but must have all digit numbers until the end.
if (expectedIntString.match("^[-|+]?\\d+$")) {  // correct format
  choice = Integer.parseInt(expectedIntString);
}
// do nothing for else because choice has default value as 0

By the way, this is not a Java forum :( It is a JavaScript forum. :P

No, for HTTP request (client side), you just send it as is. The only place where you need to check and convert is on your server side.

The server side needs to be more defensive because clients use your web page and expect that the page would be perfect. Most of the security problems from the client side are taken care by the client's browser. So coding on the client side should be able to handle any kind of input from the client side. If this involve security (which you should consider that as well), a rule of thumb is that never trust that any input from the client is secure and/or valid. In other words, validate the input as many way as you can before processing.

Thanks, I will try it now and let you know if it worked :)

Thanks again

No, for HTTP request (client side), you just send it as is. The only place where you need to check and convert is on your server side.

The server side needs to be more defensive because clients use your web page and expect that the page would be perfect. Most of the security problems from the client side are taken care by the client's browser. So coding on the client side should be able to handle any kind of input from the client side. If this involve security (which you should consider that as well), a rule of thumb is that never trust that any input from the client is secure and/or valid. In other words, validate the input as many way as you can before processing.

Hello Taywin,

I can see that this function works correctly now, however, there is a tiny mistake,

it should be matches and not match in the checking of the string, otherwise I had this exception thrown:

   at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Thread.java:619)

I should check why it threw a null POinter exception, I suppose I can add a couple of lines checking if its null or not

Thanks again

So, I have another issue now, nothing will show in the database,

I just get a null POinter exception, when I run firebug, it tells me that doPost has been aborted?

How come?

Hello Taywin,

I can see that this function works correctly now, however, there is a tiny mistake,

it should be matches and not match in the checking of the string, otherwise I had this exception thrown:

   at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Thread.java:619)

I should check why it threw a null POinter exception, I suppose I can add a couple of lines checking if its null or not

Thanks again

I think this may shed some light on the problem, I am using firefox, should I have a prevent default() method in here somewhere since I also redirect after sending the number to the server

So, I have another issue now, nothing will show in the database,

I just get a null POinter exception, when I run firebug, it tells me that doPost has been aborted?

How come?

Hmm... I don't see your Java code so I can't really tell you what's wrong. Also, prevent default() doesn't do anything for you if you are not blocking users from pressing certain key from the keyboard. It prevent from letting key listener to act as its default functionality (i.e. press F1 on the browser to show 'help').

The NullPointer from doPost means it didn't get anything back from the server. In other words, the problem is still in the server side.

I have seperated each of the function in two different servers and it seems to work just fine..

But, firebug tells me Aborted, although the request has been sent, what does that mean

Hmm... I don't see your Java code so I can't really tell you what's wrong. Also, prevent default() doesn't do anything for you if you are not blocking users from pressing certain key from the keyboard. It prevent from letting key listener to act as its default functionality (i.e. press F1 on the browser to show 'help').

The NullPointer from doPost means it didn't get anything back from the server. In other words, the problem is still in the server side.

OK, you mean it works OK now? That's great. Just ignore the abort warning. As a I told you before, the HTTP response can be sent back multiple times and Firebug discards the duplicates but still display what it does on the debug console.

I'm so happy I learned to debug this :P

thanks for redirecting me to the right way

OK, you mean it works OK now? That's great. Just ignore the abort warning. As a I told you before, the HTTP response can be sent back multiple times and Firebug discards the duplicates but still display what it does on the debug console.

You are welcome. Please mark it as solved. :)

solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.