仍在尝试使用 Spring 框架来解决我的问题,所以我提前为我闪亮的新事物道歉。
我正在努力让 Ajax 发挥作用,但结果并不理想。
这是控制器代码,这只是我试图开始工作的东西,所以它可能看起来微不足道:
@RequestMapping("/rest/login")
public @ResponseBody CallManager logIn() throws ServletException {
callManager.removeStationId();
return callManager;
}
这是相关的web.xml
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
这是 myservlet-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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<import resource="database-c3p0.xml" />
<context:annotation-config/>
<mvc:annotation-driven />
<!-- the application context definition for the springapp DispatcherServlet -->
<bean id="productManager" class="org.dat.service.ProductManagerImpl">
</bean>
<bean id="priceIncrease" class="org.dat.service.PriceIncrease">
</bean>
<bean id="stationID" class="org.dat.domain.StationId">
<property name="datStation" value=""/>
</bean>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages"/>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView">
</property>
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
这是我得到的错误:
org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/myservlet/rest/login] in DispatcherServlet with name 'myservlet'
非常感谢您为使 Ajax 正常运行而提供的任何帮助。如果您需要查看其他内容,请告诉我。谢谢你。