Проблеми с приятелското съпоставяне на Url - Java Spring

Боря се с грешки в web.xml, където всички страници идват като 404, възможно е да има основен път, но не мога да съм сигурен къде е зададен и т.н.

Това е текущият ми web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app

/*
 * User
*/
@RequestMapping(value={"/user/{id}"}, method=RequestMethod.GET)
public ModelAndView profileDisplay(
        HttpServletRequest request, 
        HttpServletResponse response,
        @RequestParam(value="id", required=false) String id
) throws UnknownHostException, MongoException {
    ServiceSerlvet.appendSesssion(request);
    //get search ALL users
    BasicDBObject searchQuery = new BasicDBObject();
        searchQuery.put("_id", new ObjectId(id));
    List<DBObject> searchResponse = PersonController.searchUsers(searchQuery);      

    //System.out.println("response from search user method: "+searchResponse);

        return new ModelAndView("user", "people", searchResponse);
}
5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app

/*
 * User
*/
@RequestMapping(value={"/user/{id}"}, method=RequestMethod.GET)
public ModelAndView profileDisplay(
        HttpServletRequest request, 
        HttpServletResponse response,
        @RequestParam(value="id", required=false) String id
) throws UnknownHostException, MongoException {
    ServiceSerlvet.appendSesssion(request);
    //get search ALL users
    BasicDBObject searchQuery = new BasicDBObject();
        searchQuery.put("_id", new ObjectId(id));
    List<DBObject> searchResponse = PersonController.searchUsers(searchQuery);      

    //System.out.println("response from search user method: "+searchResponse);

        return new ModelAndView("user", "people", searchResponse);
}
5.xsd" id="WebApp_ID" version="2.5"> <display-name>Spring3MVC</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>spring</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app>

Моят слушател контролер е така

/*
 * User
*/
@RequestMapping(value={"/user/{id}"}, method=RequestMethod.GET)
public ModelAndView profileDisplay(
        HttpServletRequest request, 
        HttpServletResponse response,
        @RequestParam(value="id", required=false) String id
) throws UnknownHostException, MongoException {
    ServiceSerlvet.appendSesssion(request);
    //get search ALL users
    BasicDBObject searchQuery = new BasicDBObject();
        searchQuery.put("_id", new ObjectId(id));
    List<DBObject> searchResponse = PersonController.searchUsers(searchQuery);      

    //System.out.println("response from search user method: "+searchResponse);

        return new ModelAndView("user", "people", searchResponse);
}

Това е текущата грешка, която излиза. Защо не се картографира, как да поправя това?

INFO: Server startup in 5904 ms
01-Nov-2012 19:40:21 org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/springApp21] in DispatcherServlet with name 'spring'
01-Nov-2012 19:40:22 org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver handleNoSuchRequestHandlingMethod
WARNING: No matching handler method found for servlet request: path '/user', method 'GET', parameters map['id' -> array<String>['4fa6eddc0234964172522248']]
01-Nov-2012 19:40:24 org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver handleNoSuchRequestHandlingMethod
WARNING: No matching handler method found for servlet request: path '/user', method 'GET', parameters map['id' -> array<String>['4fa6eddc0234964172522248']]

person Community    schedule 01.11.2012    source източник
comment
Какъв е URL адресът, който въвеждате в уеб браузъра   -  person someone    schedule 02.11.2012
comment
Когато стартирам от Eclipse като My Eclipse приложение, той също отваря страницата robot-oi772f3re:8080/springApp21   -  person    schedule 02.11.2012
comment
получавате ли начална страница или 404   -  person someone    schedule 02.11.2012
comment
Да, това е 404, изглежда иска да работи само за началната страница, ако променя ‹url-pattern›/*‹/url-pattern› на ‹url-pattern›springApp21/*‹/url-pattern›, но аз съм със сигурност това не може да е правилно и след това ме отвежда само до началната страница - другите ми гранулирани съпоставяния не работят   -  person    schedule 02.11.2012
comment
Има ли параметър на свойство, който ми липсва? Бих искал да имам само един елемент на url шаблон в картографирането на web.xml и granulalr, обработван в контролерите. - Ще трябва да добавя изключения, за да гарантирам, че пътеките на изображението, js и css също няма да се обработват от контролера. Те започват с някои видове етикети за сигурност, също изброени в web.xml. Аз съм много нов в Java spring - не знам как да го настроя правилно за този вид мащабируемост.   -  person    schedule 02.11.2012


Отговори (2)


Отговорих на един от въпросите ви преди наум. Вече имам достъп до едно от моите пролетни приложения. Ето една по-добра конфигурация.

Забележете промяната в web.xml, извинявам се, но съпоставянето към /* кара всичките ви заявки да бъдат разрешени от диспечера. В известен смисъл, когато създавате цикъл, вашето първоначално картографиране ще бъде препратено от диспечера към контролера, който след това ще използва преобразувател на изгледи, за да картографира къде трябва да бъде препратена вашата заявка. Съпоставянето към /* кара съпоставянето на преобразувателя на изгледа да се обработва от диспечера.

Промяната на / кара всички некартографирани URL адреси да се обработват от диспечера, така че първоначалното ви картографиране се обработва от диспечера, който го изпраща до контролера и картографирането, създадено от вашия viewresolver, ще бъде картографирано към .jsp, което го кара да не бъде избрано до диспечера. Моите извинения.

Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->   
    <annotation-driven/>

        <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources location="/resources/" mapping="/resources/**"/> 

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/"/>
        <beans:property name="suffix" value=".jsp"/>
    </beans:bean>

    <context:component-scan base-package="package.with.controllers" />

</beans:beans>
5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->   
    <annotation-driven/>

        <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources location="/resources/" mapping="/resources/**"/> 

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/"/>
        <beans:property name="suffix" value=".jsp"/>
    </beans:bean>

    <context:component-scan base-package="package.with.controllers" />

</beans:beans>
5.xsd" id="WebApp_ID" version="2.5"> <display-name>Spring3MVC</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>spring</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>

spring-config.xml (Трябва да промените сканирането на компонента)

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->   
    <annotation-driven/>

        <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources location="/resources/" mapping="/resources/**"/> 

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/"/>
        <beans:property name="suffix" value=".jsp"/>
    </beans:bean>

    <context:component-scan base-package="package.with.controllers" />

</beans:beans>

Контролер

@RequestMapping(value={"/user/{id}"}, method=RequestMethod.GET)
public ModelAndView profileDisplay(
        HttpServletRequest request, 
        HttpServletResponse response,
        @RequestParam(value="id", required=false) String id
) throws UnknownHostException, MongoException {
    ServiceSerlvet.appendSesssion(request);
    //get search ALL users
    BasicDBObject searchQuery = new BasicDBObject();
        searchQuery.put("_id", new ObjectId(id));
    List<DBObject> searchResponse = PersonController.searchUsers(searchQuery);      

    //System.out.println("response from search user method: "+searchResponse);

        //This should display "WEB-INF/views/user.jsp" you may need to adjust.
        return new ModelAndView("user", "people", searchResponse);
}
person Kevin Bowersox    schedule 02.11.2012
comment
Помогнах му по предишен въпрос и случайно го дезинформирах как да картографира сървлета на диспечера. {id} е синтаксисът, използван за обозначаване на uri шаблон. По същество параметърът id ще бъде изтеглен от url на заявката, смятам, че това се нарича спокойствие url. - person Kevin Bowersox; 02.11.2012

Благодаря ти Kbm, че се върна при мен. Промених своя web.xml и общите съпоставяния са разрешени. Сблъсках се с проблема, който споменахте, с преминаването на файловете css,js,image.

Опитах се да добавя URL адреси за прихващане, но нещо все още не работи. http е маркиран в червено в web.xml. Когато задържа курсора на мишката над него в eclipse, той изразява

cvc-complex-type.2.4.a: Invalid content was found starting with element 'http'. One of '{"http:// java.sun.com/xml/ns/javaee":description, "http://java.sun.com/xml/ns/javaee":display-name, "http:// java.sun.com/xml/ns/javaee":icon, "http://java.sun.com/xml/ns/javaee":distributable, "http:// java.sun.com/xml/ns/javaee":context-param, "http://java.sun.com/xml/ns/javaee":filter, "http:// java.sun.com/xml/ns/javaee":filter-mapping, "http://java.sun.com/xml/ns/javaee":listener, "http:// java.sun.com/xml/ns/javaee":servlet, "http://java.sun.com/xml/ns/javaee":servlet-mapping, "http:// java.sun.com/xml/ns/javaee":session-config, "http://java.sun.com/xml/ns/javaee":mime-mapping, "http://java.sun.com/xml/ns/javaee":welcome-file-list, "http://java.sun.com/xml/ns/javaee":error- page, "http://java.sun.com/xml/ns/javaee":jsp-config, "http://java.sun.com/xml/ns/javaee":security- constraint, "http://java.sun.com/xml/ns/javaee":login-config, "http://java.sun.com/xml/ns/ javaee":security-role, "http://java.sun.com/xml/ns/javaee":env-entry, "http://java.sun.com/xml/ns/ javaee":ejb-ref, "http://java.sun.com/xml/ns/javaee":ejb-local-ref, "http://java.sun.com/xml/ns/ javaee":service-ref, "http://java.sun.com/xml/ns/javaee":resource-ref, "http://java.sun.com/xml/ns/ javaee":resource-env-ref, "http://java.sun.com/xml/ns/javaee":message-destination-ref, "http:// java.sun.com/xml/ns/javaee":persistence-context-ref, "http://java.sun.com/xml/ns/ javaee":persistence-unit-ref, "http://java.sun.com/xml/ns/javaee":post-construct, "http:// java.sun.com/xml/ns/javaee":pre-destroy, "http://java.sun.com/xml/ns/javaee":message- destination, "http://java.sun.com/xml/ns/javaee":locale-encoding-mapping-list}' is expected.

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Spring3MVC</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>
                  org.springframework.web.servlet.DispatcherServlet
              </servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

  <http auto-config='true'>
   <intercept-url pattern="/css/**" filters="none"  />
    <intercept-url pattern="/images/**" filters="none" />
    <intercept-url pattern="/js/**" filters="none" />
  </http>
</web-app>

person Community    schedule 02.11.2012
comment
Моля, публикувайте като нов въпрос или променете въпроса си...не задавайте въпроса в същата нишка, тъй като хората виждат страницата, на която няма отговор.. - person user533; 06.11.2012
comment
Здравейте Пратап, бих искал да задам нов въпрос, но моите акаунти са забранени да задават нови въпроси. Изглежда мога само да коментирам или да добавя друг отговор. Бих искал да разреша този проблем с шаблона - но засега трябва да пропусна това и да продължа да се опитвам да науча и изпълнявам други части на проекта - person ; 06.11.2012
comment
Здравей, @divine, не - не съм го взел оттогава - person ; 07.04.2017