我正在尝试向服务器发送HTTP POST请求,但我的控制器却抛出了一个URL格式错误的异常。
控制器代码
public static final String REST_SERVICE_URI = "localhost:8081/create";
接收来自服务器的请求的控制器方法
@RequestMapping(value="AddService",method = RequestMethod.POST)
@ResponseBody
public void addService(@ModelAttribute("servDetForm")) throws IOException{
//return dataServices.addService(tb);
URL serv;
URLConnection yc;
try {
serv = new URL(REST_SERVICE_URI);
yc = serv.openConnection();
try {
yc = serv.openConnection();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedReader in;
in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
这是我的JSP视图
<form:form method="POST" commandName="servDetForm" action="AddService">
<table style="appearance:dialog ">
<tr>
<td>Number</td>
<td><form:input path="Numbers"/></td>
</tr>
我错在哪里了?
http://localhost:8081/ItaxServ/create
这样。 - Sandeep Poonia