救急!action中request的数据为空,报错String index out of range: -1
public void write() throws Exception {
// TODO Auto-generated method stub
HttpServletRequest request = ServletActionContext.getRequest();;
HttpServletResponse response = ServletActionContext.getResponse();
// httpURLConnection.setRequestProperty("content-type", "text/html");
response.setContentType("text/html;charset=UTF-8");
InputStream inputStream = request.getInputStream();
// byte[] b = new BufferedReader(new InputStreamReader(inputStream)).readLine().getBytes();
byte[] b = IOUtils.toByteArray(inputStream);
System.out.println("cuowubaogao1 :"+b.length);//测试1
String str = new String(b,"UTF-8");
System.out.println("cuowubaogao2 :"+str.length());//测试2
str = str.substring(str.indexOf("{"),str.lastIndexOf("}")+1);
JSONObject j = (JSONObject) JSONObject.parse(str);
username = j.getString("username");
userpassword = j.getString("userpassword");
UserTable u = new UserTable();
u.setUsername(username);
u.setPassword(userpassword);
u.setPower(0);
UserTableDao ud = new UserTableDao();
PrintWriter pw = response.getWriter();
if(ud.queryUser(username)!=null) {
j = new JSONObject();
j.put("result", "user_error");
} else if(ud.insertUser(u)) {
j = new JSONObject();
j.put("result", "success");
} else {
j = new JSONObject();
j.put("result", "error");
}
pw.write(j.toJSONString());
pw.flush();
pw.close();测试1,2的长度都显示为0
信息: Server startup in 20104 ms
cuowubaogao1 :0
cuowubaogao2 :0

...全文
相关推荐
SpringMVC接收前台传递过来的值的实例
下面小编就为大家分享一篇SpringMVC接收前台传递过来的值的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
Elasticsearch的JAVA操作工具类,包括增删改查的封装
Elasticsearch的JAVA操作工具类,包括增删改查的封装,Elasticsearch的JAVA操作工具类,包括增删改查的封装
jsp+jdbc实现连接数据库的方法.docx
jsp+jdbc实现连接数据库的方法.docx
SpringMVC注解
SpringMVC注解@RequestParam全面解析
struts多文件上传
struts多文件上传,黑马程序方立勋资料源


