spring hello 基础案例 报错(No mapping found for HTTP request with URI [/hello] )
web的配置:
<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<!--配置监听器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Spring view分发器 -->
<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring/springMVC</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
springmvc的配置:
<?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:tx="http://www.springframework.org/schema/tx"
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/tx
http://www.springframework.org/schema/tx/spring-tx-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">
<!-- 处理器 -->
<bean name="/hello" class="com.exercise.cn.action.HelloAction"/>
<!-- ViewResolver 视图解析器 org.springframework.web.servlet.view.InternalResourceViewResolver-->
<bean id="viewResoler" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
action的代码:
package com.exercise.cn.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import com.exercise.cn.entity.User;
import com.exercise.cn.biz.impl.IuserBiz;
public class HelloAction implements Controller{
@Override
public ModelAndView handleRequest(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {
//1、收集参数、验证参数
//2、绑定参数到命令对象
//3、将命令对象传入业务对象进行业务处理
//4、选择下一个页面
ModelAndView mv = new ModelAndView();
//添加模型数据 可以是任意的POJO对象
mv.addObject("message", "Hello World!");
//设置逻辑视图名,视图解析器会根据该名字解析到具体的视图页面
mv.setViewName("hello");
System.out.println("hello");
return mv;
}
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("spring/applicationContext.xml");
IuserBiz b = (IuserBiz) ctx.getBean("userBiz");
User user = new User();
b.save(user);
}
}
错误信息:
2015-5-31 15:03:58 org.springframework.web.servlet.PageNotFound noHandlerFound
警告: No mapping found for HTTP request with URI [/hello] in DispatcherServlet with name 'springMVC'
相关推荐
实战spring mvc
NULL 博文链接:https://a330488020.iteye.com/blog/1633339
单点登录SSO原理与OIDC/SAML/CAS协议选型实战
单点登录(SSO)是一种实现跨系统统一身份认证的架构模式,其核心在于将认证逻辑从各业务系统解耦,交由可信的身份提供者(IdP)集中处理,并通过标准化协议如OIDC、SAML或CAS安全分发身份凭证。它解决了多系统重复登录带来的体验割裂、密码复用风险及运维效率低下等典型问题,在企业内网、SaaS平台和政务系统中具有广泛技术价值。OIDC凭借JWT轻量解析与移动端友好性成为互联网场景首选;SAML以XML断言和强登出广播能力支撑高合规要求环境;CAS则以极简HTTP交互适配中小团队自建需求。本文基于真实落地经验
Spring MVC 入门实例
这篇文章将教你快速地上手使用 Spring 框架. 如果你手上有一本《Spring in Action》, 那么你最好从第三部分"Spring 在 Web 层的应用--建立 Web 层"开始看, 否则那将是一场恶梦! 首先, 我需要在你心里建立起 Spring MVC 的基本概念. 基于 Spring 的 Web 应用程序接收到 http://localhost:8080/hello.do(事实上请求路径是 /hello.do) 的请求后, Spring 将这个请求交给一个名为 helloController 的程序进行处理, helloController 再调用 一个名为 hello.jsp 的 jsp 文件生成 HTML 代码发给用户的浏览器显示. 上面的名称(/hello.do, helloController, hello.jsp) 都是变量, 你可以更改. 在 Spring MVC 中, jsp 文件中尽量不要有 Java 代码, 只有 HTML 代码和"迭代(forEach)"与"判断(if)"两个jstl标签. jsp 文件只作为渲染(或称为视图 View)模板使用. 好了, 我们开始吧. 首先我们需要一个放在 WEB-INF 目录下的 web.xml 文件: web.xml: 1 2 3 7 8 9 contextConfigLocation 10 11 /WEB-INF/database.xml 12 /WEB-INF/applicationContext.xml 13 14 15 16 17 org.springframework.web.context.ContextLoaderListener 18 19 20 21 encodingFilter 22 org.springframework.web.filter.CharacterEncodingFilter 23 24 encoding 25 UTF-8 26 27 28 29 30 encodingFilter 31 *.do 32 33 34 35 ideawu 36 org.springframework.web.servlet.DispatcherServlet 37 1 38 39 40 41 <s
JSP国际化_demo
JSP国际化子例子(中,英两种语言,易懂),
《模式识别与数据挖掘》配套PPT课件
《模式识别与数据挖掘》配套PPT课件


