0
我使用Angularjs $http
服务传递对象到了Java Servlet publishStory
。而且然而这同一个servlet代码一直很好与其他请求,但在这里我得到了以下错误:意外标记END的BufferedReader以JSON对象
我研究它在互联网上,但在那里我使用找不到解决这个特定的情况下BufferedReader,因为同一个servlet可以很好地处理其他请求。
这里是我的publishStory
的servlet:
public class publishStory extends HttpServlet{
protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{
PreparedStatement pstmt = null;
Connection cn = null;
ResultSet rs = null;
boolean flag = false;
PrintWriter out = null;
try{
System.out.println("CALLING THE METHOD");
Class.forName("com.mysql.jdbc.Driver");
cn = DriverManager.getConnection("jdbc:mysql://localhost/storyboard","root","");
BufferedReader reader = request.getReader();
JSONParser parser = new JSONParser();
JSONObject juser = null;
juser = (JSONObject)parser.parse(reader);
String welcomeStoryTitle = (String)juser.get("welcomeStoryTitle");
String welcomeStoryWords = (String)juser.get("welcomeStoryWords");
String query = "INSERT INTO stories (storytitle, storytext) VALUES (?,?)";
pstmt = cn.prepareStatement(query);
pstmt.setString(1, welcomeStoryTitle);
pstmt.setString(2, welcomeStoryWords);
int i = pstmt.executeUpdate();
if(i>0)
System.out.println(welcomeStoryTitle=" : "+welcomeStoryWords);
else
System.out.println("No data inserted");
}
catch(Exception e){
e.printStackTrace();
}
}
我检索2个请求参数在这个servlet welcomeStoryTitle
和welcomeStoryWords
。
而下面是我angularjs控制器与功能实现$http
服务:
app.controller('welcomeStoryPublishCtrl', ['$log','$http',function($log,$http){
this.publishGroup = function(wsPublish){
$http({
method:'POST',
url: 'http://localhost:9090/Writer/publishStory',
header: {'Content-Type':'application/json'},
data: wsPublish
}).success(function(){});
};
}]);
我得到这个错误在那里我解析读者对象,以行:
juser = (JSONObject)parser.parse(reader);
莫非这是因为从请求中检索到的字符串的大小?
那么我的'wsPublish'数据是空的吗? –