我知道这个问题已多次重复,但我无法解决其他线程的问题,但我的问题仍然没有解决?
我使用的是eclipse-Spring和Tomcat Server
我的web.xml为:
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
<context-param>
<param-name>applicationContext</param-name>
<param-value>applicationContext.xml</param-value>
</context-param>
我的dispatcher-servlet.xml为:
<context:component-scan base-package="com.test.controller"></context:component-scan>
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean> </i>
applicationContext.xml as:
<bean id="dataSourceBean" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost/projectdemo"></property>
<property name="username" value="root"></property>
<property name="password" value="mysql"></property>
</bean>
<bean id="sessionFactoryBean" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSourceBean"></property>
<property name="mappingResources">
<value>com/test/pojo/User.hbm.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="hibernateTemplateBean" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactoryBean"></property>
</bean>
<bean id="authenticateServiceBean" class="com.test.service.AuthticateService">
<property name="hibernateTemplate" ref="hibernateTemplateBean"></property>
</bean>
我的LoginController为:
@RequestMapping("/Login.jsp")
public class LoginController {
@Autowired
private AuthticateService authenticateService;
//@RequestMapping(value ="WEB-INF/jsp/results.jsp",method = RequestMethod.POST)
@RequestMapping(method = RequestMethod.POST)
public ModelAndView processCredentials(@RequestParam("username")String username,@RequestParam("password")String password) {
System.out.println ("in LoginController");
String message = "Invalid credentials";
if(authenticateService.verifyUserNameAndPassword(username, password)) {
System.out.println ("after IFin LoginController");
message = "Welcome " + username + "!!";
System.out.println ("after IFin LoginControllermsg" +message);
}
ModelAndView msg = new ModelAndView();
msg.setViewName("results");
msg.addObject("message",message);
System.out.println ("before return" +message);
return msg;
//return new ModelAndView("results","message",message);
}
}
results.jsp文件:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>ProjectDemo</title>
</head>
<body>
<h1><%= request.getAttribute("message") %></h1>
</body>
</html>
我在控制台中获得低于msg的信息:
userobject
User ID : 1, User name : admin, Password : admin123
after IFin LoginController
after IFin LoginControllermsgWelcome admin!!
before returnWelcome admin!!
Nov 23, 2012 11:19:08 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/projectdemo/WEB- INF/jsp/results.jsp] in DispatcherServlet with name 'dispatcher'
我收到“http:// localhost:8080 / projectdemo / Login.jsp”
输入状态报告 消息说明 请求的资源()不可用。
在控制台中,它从LoginController返回值并打印值并使用mysql数据库用户表值进行检查。
未显示“return msg”,它在控制台中显示为:
Nov 23, 2012 11:19:08 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/projectdemo/WEB-INF/jsp/results.jsp] in DispatcherServlet with name 'dispatcher'
任何人都可以帮助我吗?已经超过两天了!!!!
答案 0 :(得分:0)
你的“回复信息”
ModelAndView msg = new ModelAndView();
msg.setViewName("results");
msg.addObject("message",message);
System.out.println ("before return" +message);
return msg;
不是消息!它是一个模型(关键“消息”:值消息)和一个视图(“结果”)
视图是应呈现的jsp文件的名称。而且你没有这样的jsp文件(这就是警告No mapping found for HTTP request with URI [/projectdemo/WEB-INF/jsp/results.jsp]
抱怨的)
您需要编写此jsp文件并将其存储在/WEB-INF/jsp/results.jsp
!