0

以下是我的页面,请帮忙。

主页.jsp

        <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
     <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   "http://www.w3.org/TR/html4/loose.dtd">
       <html>
        <head>
         <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
       <title>Insert title here</title>
        <link type="text/css" rel="stylesheet" href="css/homepage.css">
         <link type="text/css" rel="stylesheet" href="css/datepickerJqueryUI.css">
        <script src="js/homepage.js"></script>
          <script src="js/jquery.js"></script>
          <script src="js/jquery-1.7.1.min.js"></script>
         <script src="js/jquery.datepicker.min.js"></script>
       <script>
         $(function() {
               $( "#datepickerDeparture" ).datepicker();
         });
        $(function() {
                $( "#datepickerReturn" ).datepicker();
              })
          </script> 
         </head>
      <body>
       <div class="headerBackground">
      <!-- Headers for Logo and menu items -->
         <div class="header">
     <div class="logo"><a href="" target="_self"></a></div>
            <div class="menu">
         Menu List Items
            </div>
         </div>
          </div>
    <!-- Division for items between the logo header and footer -->
          <div class="body">
     <!-- Division for search -->
      <div class="searchBox" >
       <form action="search" method="get" name="searchBus">
         <div class="searchLeavingFrom">Leaving from : <input type="text" name="from" class="txtBox"><h6 id="leavingFrom" class="errorMsg"></h6></div>
          <div class="searchGoingTo">Going To :<input type="text" name="destination" class="txtBox"><h6 id="destination" class="errorMsg"></h6></div>
            <div class="searchDepartOn">Depart On:<input type = "text"  name="departureDate" class="txtBox" id="datepickerDeparture"><h6 id="departure" class="errorMsg"></h6></div>
            <div class="searchReturn">Return On:<input type = "text"  name="returnDate" class="txtBox" id="datepickerReturn"></div>
            <div><input type="button" name="search" value="Search Buses" class="searchBtn"                                     onClick="validateForm()"></div>
                </form>
               </div>
               </div>
               <!-- Division for footer -->
             <div>
             </div>
           </body>
         </html>

web.xml

       <web-app id="WebApp_ID" version="2.4"
       xmlns="http://java.sun.com/xml/ns/j2ee" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
       http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

         <display-name>TicketStore</display-name>
         <welcome-file-list>
          <welcome-file>home.jsp</welcome-file>
           </welcome-file-list>

        <servlet>
           <servlet-name>TicketStore</servlet-name>
           <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
              </servlet-class>
               <init-param>
                    <param-name>contextConfigLocation</param-name>
                <param-value>/WEB-INF/TicketStore-servlet.xml</param-value>
                  </init-param>
           <load-on-startup>1</load-on-startup>
     <!--- my servlet mapping if we put as .jsp it doesnt run at all i mean homepage doesnt display at all-->
   </servlet>

    <servlet-mapping>
       <servlet-name>TicketStore</servlet-name>
          <url-pattern>*.do</url-pattern>
        </servlet-mapping>
     </web-app>

TicketStore-servlet.xml

    <?xml version="1.0" encoding="UTF-8"?>

    <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

               <bean 
       class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />

     <bean name="search"  id="search" class="com.ticketgoose.controller.SearchDetails">
          <property name="formView" value="home" />
          <property name="successView" value="searchBuses" />

        </bean>

        <!-- Register the Customer.properties -->

             <bean id="viewResolver"
             class="org.springframework.web.servlet.view.InternalResourceViewResolver">
           <property name="prefix">
            <value>/</value>
             </property>
             <property name="suffix">
                  <value>.jsp</value>
             </property>
           </bean>
         </beans>

SearchDetails.java

   package com.ticketgoose.controller;

   import com.ticketgoose.form.SearchForm;
   import org.springframework.stereotype.Controller;
   import org.springframework.validation.BindingResult;
   import org.springframework.web.bind.annotation.ModelAttribute;
   import org.springframework.web.bind.annotation.RequestMapping;
   import org.springframework.web.bind.annotation.RequestMethod;
   import org.springframework.web.bind.annotation.SessionAttributes;
   import org.springframework.web.servlet.ModelAndView;

     @Controller
     @SessionAttributes
       public class SearchDetails {
      @RequestMapping (value = "/search", method = RequestMethod.GET)
          public String addContact(@ModelAttribute("searchDetails") 
                        SearchForm searchDetails, BindingResult                             result){


      System.out.println("From:" + searchDetails.getFrom() + 
               "  To:" + searchDetails.getDestination());

          return "redirect:searchBus.html";
   }
      @RequestMapping("/searchBus")
      public ModelAndView showContacts() {
          return new ModelAndView("searchDetails", "command", new SearchForm());
      }
      }

搜索总线.jsp

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" http://www.w3.org/TR/html4/loose.dtd">

       <html>
       <head>

      <title>Success Page</title>

      </head>

      <body>

      User Details

      <hr>

               From           : ${user.name}
               To             : ${user.gender}
              Date of jourey: ${user.country}
              Return journey: ${user.aboutYou}

       </body>
       </html>

这是我的表格:

SearchForm.java

    package com.ticketgoose.form;

    import java.sql.Date;

    public class SearchForm {

String from;

String destination;

Date departureDate;

Date returnDate;
    //getter setters

public String getFrom() {

    return from;
}


public void setFrom(String from) {

    this.from = from;
}



public String getDestination() {
    return destination;
}
public void getDestination(String Destination) {

    this.destination = Destination;
}

public Date getDepartureDate() {

    return departureDate;
}


public void setDepartureDate(Date departureDate) {
    this.departureDate = departureDate;
}


public Date getReturnDate() {

    return returnDate;
}


public void setReturnDate(Date returnDate) {

this.returnDate = returnDate;
}}

请帮我解决这个问题,我根本无法弄清楚问题所在。

4

2 回答 2

0

您的应用程序是否在 Web 服务器上的应用程序上下文中运行?

尝试这个:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<form action="<c:url value="/search" />" method="get" name="searchBus">
于 2013-08-08T12:03:54.897 回答
0

表单的动作说 action="search"

 <form action="search" method="get" name="searchBus">

但是,在您的 web.xml 中,您的 spring 映射是*.do

 <servlet-mapping>
       <servlet-name>TicketStore</servlet-name>
       <url-pattern>*.do</url-pattern>
 </servlet-mapping>

通过action="search.do"更改action="search "

或通过(不推荐)更改映射

<servlet-mapping>
       <servlet-name>TicketStore</servlet-name>
       <url-pattern>*</url-pattern>
 </servlet-mapping>
于 2013-08-13T03:53:02.353 回答