我正在修改我在特定站點上找到的項目。 問題是當我在服務器上運行項目時,顯示包含美國地圖的home.jsp頁面。我使地圖可點擊。當我點擊地圖狀態時,生成的新URL爲localhost:7001/SpringMVCAngularJS/home.jsp?statechoice=ME
。按照Spring mvc邏輯,應該調用getUSCity()方法。但它沒有被調用。即使我只碰到localhost:7001/SpringMVCAngularJS/home.jsp
,它也沒有被調用。 而如果我點擊localhost:7001/SpringMVCAngularJS/springAngularJS.web
,則會調用特定的方法。如果我缺少任何映射等,你能告訴我嗎?控制器方法沒有在春天調用mvc
@Controller
public class SpringMVCController {
@Autowired
Top10LanesService lanesService;
@RequestMapping(value = "/angularJS.web", method = RequestMethod.GET)
public String printWelcome(ModelMap model) {
return "Home";
}
@RequestMapping(value = "/springAngularJS.web", method = RequestMethod.GET, produces = { "application/xml",
"application/json" })
public @ResponseBody List<LmWebShipment> getTop10Lanes() {
List<LmWebShipment> al = new ArrayList<LmWebShipment>();
// Top10LanesDAOImpl top10LanesDaoImpl = new Top10LanesDAOImpl();
al = lanesService.getTop10Lanes();
return al;
}
// Called on Click of US state
@RequestMapping(value = "/home.web", method = RequestMethod.GET, produces = { "application/xml",
"application/json" })
@ResponseBody
public void getUSCity(@PathVariable("statechoice") String statechoice) {
System.out.println("In getUSCity" + statechoice);
}
}
我在我的home.jsp文件中有這樣的東西。
<area shape='polygon' coords='489,52,502,31,513,32,518,54,490,71' href='home.jsp?statechoice=ME' target="right" alt='Maine'>
分配器一servlet.xml中
<context:property-placeholder location="classpath:database/database.properties"/>
<context:component-scan base-package="com.javahonk.controller" />
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/Views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<!-- bind messages.properties -->
<bean class="org.springframework.context.support.ResourceBundleMessageSource"
id="messageSource">
<property name="basename" value="messages/messages" />
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driver}"></property>
<property name="url" value="${jdbc.url}"></property>
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="top10LanesDAO" class="com.javahonk.DAO.Top10LanesDAOImpl" />
<bean id="top10LanesService" class="com.javahonk.services.Top10LanesServiceImpl" />
</beans>
的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"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.web</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>angularJS.web</welcome-file>
</welcome-file-list>
<display-name>SpringAngularJS</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
由於路徑變量,我得到了400錯誤。我沒有嘗試解決方案,但問題是路徑變量。我改用參數的請求參數。 – themaster
好,好吧,這將使它更容易 –