- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我刚刚尝试调用index.jsp
它使用 http POST 将 json 发送到我的 rest 项目。
但这给我带来了这个错误:
我无法弄清楚问题出在哪里
任何提示?我对此没有想法。
org.apache.catalina.core.StandardWrapperValve invokeGRAVE: Servlet.service() for servlet [jersey-serlvet] in context with path [/HibernateTutorialWeb] threw exception [org.codehaus.jackson.JsonParseException: Unexpected character ('a' (code 97)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')at [Source: org.apache.catalina.connector.CoyoteInputStream@24097548; line: 1, column: 2]] with root causeorg.codehaus.jackson.JsonParseException: Unexpected character ('a' (code 97)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')at [Source: org.apache.catalina.connector.CoyoteInputStream@24097548; line: 1, column: 2]at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1213)at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:375)at org.codehaus.jackson.impl.JsonParserMinimalBase._reportUnexpectedChar(JsonParserMinimalBase.java:306)at org.codehaus.jackson.impl.Utf8StreamParser._handleUnexpectedValue(Utf8StreamParser.java:1536)at org.codehaus.jackson.impl.Utf8StreamParser._nextTokenNotInObject(Utf8StreamParser.java:432)at org.codehaus.jackson.impl.Utf8StreamParser.nextToken(Utf8StreamParser.java:318)at org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2168)at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2106)at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1004)at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:410)at com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy.readFrom(JacksonProviderProxy.java:139)at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:474)at com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:123)at com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:46)at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:153)at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:203)at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)at java.lang.Thread.run(Unknown Source)
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Send jSon - put method</title>
</head>
<body>
<script>
//var people = {"address": "Address 12", "name": "twelve", "id": 12,"surname": "twelve"};
var people={"address": "hello"};
function sendobject(){
$.ajax({
type: "POST",
url: "http://localhost:8080/HibernateTutorialWeb/rest/person/post",
data: people,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data){alert(data);},
failure: function(errMsg) {
alert(errMsg);
}
});
}
</script>
<input type="button" onclick="sendobject()" value="invia"> </input>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
</body>
</<html>
人员服务。 java
package com.ws.service;
import java.util.List;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import com.dao.*;
import com.model.*;
@Path("/person")
public class PersonService {
// try hello data
// http://localhost:8080/HibernateTutorialWeb/rest/person/hello/mario
@GET
@Path("/hello/{param}")
public Response getMsg(@PathParam("param") String msg) {
String output = "Jersey say hello : " + msg;
return Response.status(200).entity(output).build();
}
// http://localhost:8080/HibernateTutorialWeb/rest/person/2
@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
public Person getPersonById(@PathParam("id") int id) {
return new PersonDao().getPersonById(id);
// error for type of response incorrect
/*
* public ResponseBuilder getPersonById(@PathParam("id") int id){
* PersonDao pDao = new PersonDao (); if(pDao.getPersonById(id) != null)
* {return Response.status(200).entity(new
* PersonDao().getPersonById(id));} else{ return
* Response.status(200).entity("Utente id: "+ id + ", Rimosso"); }
*/
}
// //http://localhost:8080/HibernateTutorialWeb/rest/person/getAllJson
@GET
@Path("/getAllJson")
@Produces(MediaType.APPLICATION_JSON)
public List<Person> getAllJson() {
return new PersonDao().getAllPerson();
}
@GET
@Path("/xml/{id}")
@Produces(MediaType.APPLICATION_XML)
public Person getPersonByIdXML(@PathParam("id") int id) {
return new PersonDao().getPersonById(id);
}
@POST
@Path("/post")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response createUtenteJSON(Person person) {
new PersonDao().saveOrUpdate(person);
String result = "Person saved : " + person;
return Response.status(201).entity(result).build();
}
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public Response updateUtente(Person person) {
if (person.getId() != 0) {
new PersonDao().saveOrUpdate(person);
return Response.ok(person, MediaType.APPLICATION_JSON).build();
} else {
return Response.status(Response.Status.BAD_REQUEST)
.entity("Specificare l'id dell'utente").build();
}
}
@DELETE
@Path("{id}")
public Response removePerson(@PathParam("id") Integer id) {
new PersonDao().deletePerson(id);
return Response.status(200).entity("Utente id: " + id + ", Rimosso")
.build();
}
}
PersonDao.java
package com.dao;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.model.Person;
import com.util.SessionFactoryUtil;
public class PersonDao {
public void saveOrUpdate(Person person) {
Transaction trns = null;
Session session = SessionFactoryUtil.getSessionFactory().openSession();
try {
trns = session.beginTransaction();
if (person.getId() != 0) {
//if exists update obj
session.update(person);
} else {
session.save(person);
}
session.getTransaction().commit();
} catch (RuntimeException e) {
if (trns != null) {
trns.rollback();
}
e.printStackTrace();
} finally {
session.flush();
session.close();
}
}
public void deletePerson(int id) {
Transaction trns = null;
Session session = SessionFactoryUtil.getSessionFactory().openSession();
try {
trns = session.beginTransaction();
Person person = (Person) session.load(Person.class, new Integer(id));
System.out.println("Deleted person :"+person.toString());
session.delete(person);
session.getTransaction().commit();
} catch (RuntimeException e) {
if (trns != null) {
trns.rollback();
}
e.printStackTrace();
} finally {
session.flush();
session.close();
}
}
public List<Person> getAllPerson() {
List<Person> people = new ArrayList<Person>();
Transaction trns = null;
Session session = SessionFactoryUtil.getSessionFactory().openSession();
try {
trns = session.beginTransaction();
people = session.createQuery("from Person").list();
//session.getTransaction().commit();
} catch (RuntimeException e) {
if (trns != null) {
trns.rollback();
}
} finally {
session.flush();
session.close();
}
System.out.println("People list : \n");
for(int i=0;i<people.size();i++){
System.out.println(people.get(i));
}
return people;
}
public Person getPersonById(int id) {
Person person = null;
Transaction trns = null;
Session session = SessionFactoryUtil.getSessionFactory().openSession();
try {
trns = session.beginTransaction();
String queryString = "FROM Person WHERE id = :id";
Query query = session.createQuery(queryString);
query.setInteger("id", id);
person = (Person) query.uniqueResult();
} catch (RuntimeException e) {
e.printStackTrace();
} finally {
session.flush();
session.close();
}
return person;
}
}
更新:
var people = JSON.parse({"address": "Indirizzo 12", "name": "dodici", "id": 12,"surname": "dodici"});
现在错误是这样的:
HTTP Status 500 - java.io.EOFException: No content to map to Object due to end of input
type Exception report
message java.io.EOFException: No content to map to Object due to end of input
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: java.io.EOFException: No content to map to Object due to end of input
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.io.EOFException: No content to map to Object due to end of input
org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2173)
org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2106)
org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1004)
org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:410)
com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy.readFrom(JacksonProviderProxy.java:139)
com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:474)
com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:123)
com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:46)
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:153)
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:203)
com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
最佳答案
尝试更改Object
至JSON
线:
var people={"address": "ciao"};
var people=JSON.stringify(eval({"address": "ciao"}));
Person
类具有您传递给它的相同参数构造函数。
Hibernate
异常(exception)
StaleStateException意思是:
Thrown when a version number or timestamp check failed, indicating that the Session contained stale data (when using long transactions with versioning). Also occurs if we try delete or update a row that does not exist
关于java - 意外字符 ('a'(代码 97)) : expected a valid value (number, 字符串、数组、对象、 'true'、 'false' 或 'null'),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33631523/
从 angular 5.1 更新到 6.1 后,我开始从我的代码中收到一些错误,如下所示: Error: ngc compilation failed: components/forms/utils.
我正在学习 Typescript 并尝试了解类型和接口(interface)的最佳实践。我正在玩一个使用 GPS 坐标的示例,想知道一种方法是否比另一种更好。 let gps1 : number[];
type padding = [number, number, number, number] interface IPaddingProps { defaultValue?: padding
这两种格式在内存中保存结果的顺序上有什么区别吗? number = number + 10; number += 10; 我记得一种格式会立即保存结果,因此下一行代码可以使用新值,而对于另一种格式,
在 Python 匹配模式中,如何匹配像 1 这样的文字数字在按数字反向引用后 \1 ? 我尝试了 \g用于此目的的替换模式中可用的语法,但它在我的匹配模式中不起作用。 我有一个更大的问题,我想使用一
我的源文件here包含 HTML 代码,我想将电话号码更改为可在我的应用程序中单击。我正在寻找一个正则表达式来转换字符串 >numbernumber(\d+)$1numbernumber<",我们在S
我们有一个包含 2 个字段和一个按钮的表单。我们想要点击按钮来输出位于 int A 和 int B 之间的随机整数(比如 3、5 或 33)? (不需要使用 jQuery 或类似的东西) 最佳答案 你
我收到以下类型错误(TypeScript - 3.7.5)。 error TS2345: Argument of type '(priority1: number, priority2: number
只想创建简单的填充器以在其他功能中使用它: function fillLine(row, column, length, bgcolor) { var sheet = SpreadsheetApp
我有一个问题。当我保存程序输出的 *.txt 时,我得到以下信息:0.021111111111111112a118d0 以及更多的东西。 问题是: 这个数字中的“d0”和“a”是什么意思? 我不知道“
首先:抱歉标题太长了,但我发现很难用一句话来解释这个问题;)。是的,我也四处搜索(这里和谷歌),但找不到合适的答案。 所以,问题是这样的: 数字 1-15 将像这样放在金字塔中(由数组表示):
我想从字符串中提取血压。数据可能如下所示: text <- c("at 10.00 seated 132/69", "99/49", "176/109", "10.12 I 128/51, II 1
当尝试执行一个简单的 bash 脚本以将前面带有 0 的数字递增 1 时,原始数字被错误地解释。 #!/bin/bash number=0026 echo $number echo $((number
我有一个类型为 [number, number] 的字段,TypeScript 编译器(strict 设置为 true)出现问题,提示初始值值(value)。我尝试了以下方法: public shee
你能帮我表达数组吗:["232","2323","233"] 我试试这个:/^\[("\d{1,7}")|(,"\d{1,7}")\]$/ 但是这个表达式不能正常工作。 我使用 ruby(rail
这个问题在这里已经有了答案: meaning of (number) & (-number) (4 个回答) 关闭6年前. 例如: int get(int i) { int res = 0;
我正在考虑使用 Berkeley DB作为高度并发的移动应用程序后端的一部分。对于我的应用程序,使用 Queue对于他们的记录级别锁定将是理想的。但是,如标题中所述,我需要查询和更新概念建模的数据,如
我正在尝试解决涉及重复数字的特定 JavaScript 练习,为此我需要将重复数字处理到大量小数位。 目前我正在使用: function divide(numerator, denominator){
我有这个数组类型: interface Details { Name: string; URL: string; Year: number; } interface AppState {
我们正在使用 Spring 3.x.x 和 Quartz 2.x.x 实现 Web 应用程序。 Web 服务器是 Tomcat 7.x.x。我们有 3 台服务器。 Quartz 是集群式的,因此所有这
我是一名优秀的程序员,十分优秀!