在index.jsp上登录——>login.jsp页面。
login.jsp上有两个静态的连接add.jsp和sel.jsp
然后点add.jsp 是一个添加用户的表单 输入数据提交后
没有任何显示 debug报:
2015-11-20 11:06:56,613 [http-bio-9090-exec-10] DEBUG [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] - Looking up handler method for path /view/adduser
2015-11-20 11:06:56,616 [http-bio-9090-exec-10] DEBUG [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] - Did not find handler method for [/view/adduser]
2015-11-20 11:06:56,617 [http-bio-9090-exec-10] DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - Matching patterns for request [/view/adduser] are [/**]
2015-11-20 11:06:56,617 [http-bio-9090-exec-10] DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - URI Template variables for request [/view/adduser] are {}
2015-11-20 11:06:56,617 [http-bio-9090-exec-10] DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - Mapping [/view/adduser] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler@6aa25d] and 1 interceptor
2015-11-20 11:06:56,618 [http-bio-9090-exec-10] DEBUG [org.springframework.web.servlet.DispatcherServlet] - Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2015-11-20 11:06:56,618 [http-bio-9090-exec-10] DEBUG [org.springframework.web.servlet.DispatcherServlet] - Successfully completed request
我的controller :
@RequestMapping("/adduser")
public ModelAndView addUser(ModelMap model, HttpServletRequest request, HttpServletResponse response) {
ModelAndView mav = new ModelAndView("adduser");
System.out.println("添加controller被调用");
Integer userId = Integer.parseInt(request.getParameter("id").trim());
String userName = request.getParameter("uname").trim();
String userPassword = request.getParameter("upass").trim();
String userEmail = request.getParameter("email");
User user =userService.addUser(userId, userName, userPassword, userEmail);
System.out.println(user);
return mav;
}
<mvc:annotation-driven />
<mvc:default-servlet-handler /> 的配置和
<!-- 拦截设置 -->
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>都有配置。
控制台上并没有被调用的信息。请问为什么?
Did not find handler method for [/view/adduser]没有这路径,不是/adduser它,可以在你controller类上面加上@RequestMapping(“/view”)
有配置被spring扫描吗?
可以在你的类名上和方法上分别添加对应的注解信息试试,例如下面这样:
@Controller
@RequestMapping("login")
public class LoginController {
@RequestMapping(value = "adduser", method = RequestMethod.GET)
@ResponseBody
public BaseMessage queryResult(@RequestParam(value = "account", required = false) final String account,
@RequestParam(value = "mobile", required = false) final String mobile) {
BaseMessage msg = new BaseMessage();
//调用你相应的service方法
return msg;
}
}
/view/adduser
没有映射到这个位置
我将那个表单放在
调用静态jsp之前,就可以访问到controller。
请问这是为什么啊。
想让流程正常运行,该怎么修改呢??
已解决:
<form action="../adduser" method="post">
将form表单上 action 加 " ../"
原因:在项目打开后,用登录做的跳转。都是基于 项目路径下的。 也就是 相对路径。
点击前的 目录:http://localhost:9090/ssm_project/
在点击 静态Jsp超链接后。根目录发生了变化。此时的跳转action已经是 绝对路径。
点击超链接后的目录:http://localhost:9090/ssm_project/view/add.jsp
给你一个建议,对于表单等常用的页面,不要用../这种方式来跳转,因为如果在某些特别长的xx/xx/xx/xx这种URL,如果从它来转发到adduser的话,那么你再次提交,又会报这种错误
最好是以项目为相对路径写URL。
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title></title>
</head>
<body>
</body>
</html>
或者${pageContext.request.contextPath}/adduser这种方式是最安全的