我發送一個ajax請求到servlet,它顯示了500個內部服務器錯誤java.lang.NullPointerException
。但它成功發佈{「word」:「value」}。如果它通過AJAX調用成功地從客戶端發佈數據,它應該是我的servlet的東西。但無法弄清楚它到底是什麼。java.lang.NullPointerException servlet
AJAX調用
function sendAjax() {
// get inputs
var word = {
word:$('#word').val()
}
$.ajax({
url: "WordQuest",
type: 'POST',
dataType: 'json',
data: JSON.stringify(word),
contentType: 'application/json',
mimeType: 'application/json',
success: function (data) {
$('#shuffled').append(data);
},
error:function(data,status,er) {
alert("error: "+data+" status: "+status+" er:"+er);
}
});
的Servlet
public class WordQuest extends HttpServlet {
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
String requset_word = request.getParameter("word");
WordShuffle cls = new WordShuffle();
String shuffled_word = cls.shuffle(requset_word);
response.setContentType("application/json");
PrintWriter out = response.getWriter();
out.print(shuffled_word);
out.flush();
}
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
doGet(request, response);
}
}
這是堆棧跟蹤
java.lang.NullPointerException
at WordShuffle.str_to_arr(WordShuffle.java:22)
at WordShuffle.shuffle(WordShuffle.java:11)
at WordQuest.doGet(WordQuest.java:20)
at WordQuest.doPost(WordQuest.java:32)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
能否請您發佈全堆棧跟蹤? –
同時顯示請求映射以及堆棧跟蹤 –
發佈了完整堆棧跟蹤 –