当我试图在spring mvc控制器中操作表单数据时,我收到错误

时间:2013-04-29 00:10:16

标签: java spring-mvc

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

hello.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>

results.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 - 服务/ RS /酒店/ V3 /列表minorRev = 20安培; CID = 55505&放大器; apiKey = 123456789&放大器; customerUserAgent =的Mozilla / 5.0?   (Windows NT 6.2; Win64; x64;)Gecko / 20100101   火狐/ 20.0安培; customerIpAddress = 192.168.1.1和放大器;场所= EN_US和放大器; CURRENCYCODE = USD和放大器;城市=西雅图和放大器; stateProvinceCode = WA和放大器; COUNTRYCODE = US&放大器; supplierCacheTolerance = MED和放大器; arrivalDate = 9月4日/ 2013和放大器; departureDate = 9月5日/ 2013&安培; ROOM1 = 2及numberOfResults = 1&安培; supplierCacheTolerance = MED_ENHANCED

有什么想法吗? 谢谢。

0 个答案:

没有答案