Java.net.MalformedURLException: unknown protocol: localhost at controller.RestController.addService (RestController.java:62)

I am trying to make an http message on the server and I am getting a url failure from my controller.

controller code

public static final String REST_SERVICE_URI = "localhost:8081/create";

method in the controller that receives the request from the server

@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();
    }
 }

this is my jsp view

<form:form method="POST" commandName="servDetForm" action="AddService">
              <table style="appearance:dialog ">

                    <tr>
                        <td>Number</td>
                        <td><form:input path="Numbers"/></td>
                    </tr>

where is my mistake

+4
source share
2 answers

The URL should be as follows:

"http://localhost:8081/ItaxServ/create"

or maybe

"https://localhost:8081/ItaxServ/create"

( UPDATE ) I assume you have the correct path in your url. If not, you will also need to fix it.)

"http" "https" URL-, . URL- URL-. ( URI URL-.)

( URI . URL , ( "localhost" ) . ... " ".)


. :

@RequestMapping(value = "AddService", method = RequestMethod.POST)

:

@RequestMapping(value = "/create", method = RequestMethod.POST)

"/"?

+7

url URI, "REST_SERVICE_URI"

REST_SERVICE_URI , http, https ..

0

All Articles