gpt4 book ai didi

jquery - 调用ajax时出现500内部服务器错误

转载 作者:行者123 更新时间:2023-12-01 05:39:54 24 4
gpt4 key购买 nike

我正在使用 spring mvc 和 apachitile.page 通过“AddUpdateCustomer”操作进行重定向。我想在使用 ajax 重定向到页面(加载时)时将列表从 Controller 传递到 View 。我编写了代码但收到错误。不知道我的网址引用是否正确。收到错误警报。

Controller :

@RequestMapping("/AddUpdateCustomer")
public String redirectCustomer(Map<String, Object> map) {
//map.put("customerList", customerService.listCustomer());
return "AddUpdateCustomer";
}

@RequestMapping("/ListCustomer")
@ResponseBody
public List<Customer> ListCustomer() {
return customerService.listCustomer();
}
function LoadDataToThegrid() {
$.ajax({
type: "POST",
url: "ListCustomer.html",
data: {},
success: function(data){
alert(data);
},
error: function(jqXHR, textStatus, errorThrown){
//alert('Error: ' +xhr.responseText);
alert('Error: ' + jqXHR.responseText);
}
});
}

网络 XML:

<display-name>Spring3-Hibernate</display-name>
<welcome-file-list>
<welcome-file>redirect.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>

spring-servlet.xml:

<context:annotation-config />
<context:component-scan base-package="net.opticare" />


<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass">
<value>
org.springframework.web.servlet.view.tiles2.TilesView
</value>
</property>
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>

<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>

<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:location="/WEB-INF/jdbc.properties" />

<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
p:password="${jdbc.password}" />


<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>

<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven />
<tx:annotation-driven />

<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

Firebug 控制台错误:

500 Internal Server Error -http://localhost/Spring3HibernateMaven/ListCustomer.html

最佳答案

首先快速查看告诉我您应该删除 jquery ajax 调用的 url 属性中的 .html 部分。使用 .html

@RequestMapping("/ListCustomer")    
@ResponseBody
public List<Customer> ListCustomer() {

Controller 方法永远不会被调用。

关于jquery - 调用ajax时出现500内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31337630/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com