0

好的,我在这里做错了,但我不知道是什么。所以这里是代码:

你好.jspx:

<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" xmlns="http://www.w3.org/1999/xhtml" version="2.0">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <jsp:output omit-xml-declaration="yes"/>
    <html>
    <head><title>Simple jspx page</title></head>
    <body>
    Place content here ${message}

    <form method="get" action="sendParameters">
    <table>
        <tr>
            <td>City:</td>
            <td><input type="text" name="cityName" id="cityId"/></td>
        </tr>
        <tr>
            <td>State:</td>
            <td><input type="text" name="stateName" id="stateId"/></td>
        </tr>
        <tr>
            <td>Arrival Date:(MM/DD/YYYY)</td>
            <td><input type="text" name="arrivalDateName" id="arrivalDateId"/></td>
        </tr>
        <tr>
            <td>Departure Date:(MM/DD/YYYY)</td>
            <td><input type="text" name="departureDateName" id="departureDateId"/></td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit" value="Submit"/>
            </td>
        </tr>
    </table>
    </form>

    </body>
    </html>
</jsp:root>

结果.jspx:

<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" xmlns="http://www.w3.org/1999/xhtml" version="2.0">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <jsp:output omit-xml-declaration="yes"/>
    <html>
    <head><title>Simple jspx page</title></head>
    <body>Place content here : ${message}</body>
    </html>
</jsp:root>

HomeController.java:

package com.apress.prospring3.ch17.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

@Controller
@RequestMapping("/")
public class HomeController {
    @RequestMapping(method = RequestMethod.GET)
    public String printWelcome(ModelMap model)
    {
        model.addAttribute("message", "Hello user!");
        return "hello";
    }

    @RequestMapping(value="/sendParameters", method = RequestMethod.GET)
    public String createUrl(ModelMap model, @RequestParam("cityName")String cityName, @RequestParam("stateName")String stateName, @RequestParam("arrivalDateName")String arrivalDateName, @RequestParam("departureDateName")String departureDateName) throws Exception
    {
        String myUrl = "http://api.ean.com/ean‑services/rs/hotel/v3/list?minorRev=20" +
                "&cid=55505" +
                "&apiKey=123456789" +
                "&customerUserAgent=Mozilla/5.0 (Windows NT 6.2; Win64; x64;) Gecko/20100101 Firefox/20.0" +
                "&customerIpAddress=192.168.1.1" +
                "&locale=en_US" +
                "&currencyCode=USD" +
                "&city=" + cityName +
                "&stateProvinceCode=" + stateName +
                "&countryCode=US" +
                "&supplierCacheTolerance=MED" +
                "&arrivalDate=" + arrivalDateName +
                "&departureDate=" + departureDateName +
                "&room1=2" +
                "&numberOfResults=1" +
                "&supplierCacheTolerance=MED_ENHANCED";

        URL yahoo = new URL(myUrl);
        URLConnection yc = yahoo.openConnection();
        BufferedReader in = new BufferedReader(
                new InputStreamReader(
                        yc.getInputStream()));
        String inputLine;

        while ((inputLine = in.readLine()) != null)
            System.out.println(inputLine);
        in.close();

        model.addAttribute("message", "Results ready!");
        return "results";
    }
}

在我按下提交后出现错误,如下所示:

HTTP 状态 500 - 服务器返回 HTTP 响应代码:400 用于 URL: http : //api.ean.com/ean -services/rs/hotel/v3/list?minorRev=20&cid=55505&apiKey=123456789&customerUserAgent=Mozilla/5.0 (Windows NT 6.2; Win64; x64;) Gecko/20100101 Firefox/20.0&customerIpAddress=192.168.1.1&locale=en_US¤cyCode=USD&city=Seattle&stateProvinceCode=WA&countryCode=US&supplierCacheTolerance=MED&arrivalDate=09/04/2013&departureDate=09/05/2013&room1=2&numberOfResults=1&supplierCacheTolerance=MED_ENHANCED

有任何想法吗?谢谢你。

4

0 回答 0