照着书上写的一个springMVC跳转的例子
web.xml文件是这样的:
<?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_3_0.xsd" id="WebApp_ID" version="3.0">
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 初始化参数 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcherServlet-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- 拦截所有以do结尾的请求 -->
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
dispatcherServlet-servlet.xml文件是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframeword.org/dtd/spring-beans.dtd">
<beans>
<!-- 定义映射 -->
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="helloWorld.do">helloWorldAction</prop>
</props>
</property>
</bean>
<!-- 定义视图 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.InternalResourceView</value>
</property>
</bean>
<!-- 定义控制器 -->
<bean id="helloWorldAction" class="com.moon.action.HelloWorldAction">
<property name="helloWorld">
<value>HelloWorld</value>
</property>
<property name="viewPage">
<value>/WEB-INF/jsp/index.jsp</value>
</property>
</bean>
</beans>
index.jsp是这样的:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!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=utf-8">
<title>Insert title here</title>
</head>
<%
String str = (String)request.getAttribute("helloWorld");
%>
<body>
<h1><%=str %></h1>
</body>
</html>
目录结构是这样的:
开始以为是路径跳转问题,可是找了半天也没发现问题
可能我一个人太局限了暂时没找到点上
大家能不能帮忙找一下是哪里出了错
------解决思路----------------------
tomcat 报这个错误,是你的配置文件有误,
你检查一下你配置的路径,和类名字的大小写有没有写对。。。
设置的参数不要手打,直接复制试试
------解决思路----------------------
jar包都齐全?启动报错吗?