ajax请求controller请求不到

qq_28054181 2015-08-07 11:52:11
...全文
1120 点赞 收藏 16
写回复
16 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
陈岩松 2015-08-14
@ResponseBody
回复
为何你的controller上面是 / ? 这样能行?
回复
忧伤等待 2015-08-12
你貌似没写前缀吧!
回复
S60n4s623 2015-08-07
URL写错了吧,后缀不是.do吗
回复
qq_28054181 2015-08-07
<?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:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" 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-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <!-- 启动时扫描所有的controller --> <context:component-scan base-package="controller" /> <!-- 主要作用于@Controller,激活该模式,下面是一种简写形式,完全可以手动配置替代这种简写形式,它会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter,是spring MVC为@Controllers分发请求所必须的 --> <mvc:annotation-driven /> <!-- 配置js,css等静态文件直接映射到对应的文件夹,不被DispatcherServlet处理 --> <mvc:resources location="/WEB-INF/resources/**" mapping="/resources" /> <!-- jsp页面解析器,当Controller返回XXX字符串时,先通过拦截器,然后该类就会在/WEB-INF/views/目录下,查找XXX.jsp文件 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/" /> <property name="suffix" value=".jsp" /> </bean> </beans>
回复
qq_28054181 2015-08-07
<?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"> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:config/jdbc.xml</param-value> </context-param> <!-- spring 配置文件的加载 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:config/spring.xml</param-value> </context-param> <!-- 监听器 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- 过滤编码方式,防止乱码 --> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- springMVC的配置 --> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 加载springMVC的配置文件 --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:config/springmvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
回复
qq_28054181 2015-08-07
ajax里url总是显示找不到
回复
Ant_Shen 2015-08-07
这样配置应该是没错的,你试下在web.xml中的url-parttern改成 /
回复
qq_28054181 2015-08-07



这是在谷歌浏览器上点击登录后的结果
回复
qq_28054181 2015-08-07
@Ant_Shen 没有错误提示
回复
qq_28054181 2015-08-07
function submits() { var url="${pageContext.request.contextPath}/logins.do"; $.post(url,{username:$("#userNames").val(),password:$("#password").val()},function(data){ alert("进入"); if(data.message == 'success'){ alertMsg('登录成功!','success'); window.location.href='${pageContext.request.contextPath}/main.jsp'; }else{ alert("账号或密码有误"); } }); }
回复
Ant_Shen 2015-08-07
应该是xxx/logins.do,不要写错了,能否把错误贴出来,详细
回复
qq_28054181 2015-08-07
@qkjoe @Ant_Shen @rui888 @somnus623 加了.do还是没反应~~~~~~~~
回复
qkjoe 2015-08-07
同楼上,默认设置的过滤方式是以.do结尾,所以url最后也应该加个.do
回复
Ant_Shen 2015-08-07
web.xml中 <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> 这里指定拦截的url以.do结尾 修改一下url,或者url-pattern
回复
兔子托尼啊 2015-08-07
url 不对哦。
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2015-08-07 11:52
社区公告
暂无公告