我尝试用java把object通过http post 方式发送到play framework连接的mysql中,我不太清楚play framework中的 id怎么处理,返回的错误如下
---------------------------------------------------
java送信端
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:9000/Application/show
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sqlPost.SqlPost.httpPost(SqlPost.java:37)
at sqlPost.SqlPost.main(SqlPost.java:47)
---------------------------------------------------
play framework端
Internal Server Error (500) for request POST /Application/show
Execution exception (In /app/controllers/Application.java around line 27)
IllegalArgumentException occured : id to load is required for loading
play.exceptions.JavaExecutionException: id to load is required for loading
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:231)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.IllegalArgumentException: id to load is required for loadin
g
at org.hibernate.event.LoadEvent.<init>(LoadEvent.java:89)
at org.hibernate.event.LoadEvent.<init>(LoadEvent.java:61)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:1002)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:998)
at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManage
rImpl.java:614)
at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManage
rImpl.java:589)
at play.db.jpa.JPQL.findById(JPQL.java:36)
at models.AuctionItem.findById(AuctionItem.java)
at controllers.Application.show(Application.java:27)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
... 1 more
---------------------------------------------------
java发送端代码
package sqlPost;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
public class SqlPost {
public void httpPost() throws IOException {
// Create Post String
// String data = URLEncoder.encode("myName", "UTF-8") + "="+
// URLEncoder.encode("ttgg", "UTF-8");
AuctionItem item = new AuctionItem();
item.title = "Football";
item.days = 11;
item.startBid = (float) 1;
item.buyNowEnabled = true;
item.buyNowPrice = (float) 20;
item.deliveryCost = (float) 5;
item.description = "this football is a new one";
// Send Data To Page
URL url = new URL("http://localhost:9000/Application/show");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
// OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
ObjectOutputStream oos = new ObjectOutputStream(conn.getOutputStream());
oos.writeObject(item);
oos.flush();
// Get The Response
BufferedReader rd = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
System.out.println(line);
// you Can Break The String Down Here
}
}
public static void main(String args[]) throws Exception {