ajax请求controller请求不到

qq_28054181 2015-08-07 11:52:11
...全文
1252 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
陈岩松 2015-08-14
  • 打赏
  • 举报
回复
@ResponseBody
  • 打赏
  • 举报
回复
为何你的controller上面是 / ? 这样能行?
忧伤等待 2015-08-12
  • 打赏
  • 举报
回复
你貌似没写前缀吧!
somnus623 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
tony4geek 2015-08-07
  • 打赏
  • 举报
回复
url 不对哦。

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧