0

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?

2
Contributors
19
Replies
20
Views
6 Years
Discussion Span
Last Post by omaiaa0p
0

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.

Edited by Taywin: n/a

0

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.

0

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

Edited by Taywin: n/a

0

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

0

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).

Edited by Taywin: n/a

0

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).

0

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

0

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

0

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.

0

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.

0

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

Edited by mike_2000_17: Fixed formatting

0

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

Edited by mike_2000_17: Fixed formatting

0

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?

Edited by mike_2000_17: Fixed formatting

0

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.

0

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.

0

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.

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.