spring mvc 无法加载jsp页面

一个spring mvc的实验,里面的页面html的就好用,换成jsp就500 ,求解!!!

项目情况:

见附件的图片。

 

配置文件:

1.applicationContext.xml

   <bean id="userDao" class="cn.edgedu.dao.impl.UserDaoMysqlImpl"></bean>
    <bean id="userService" class="cn.edgedu.service.impl.UserServiceImpl">
        <property name="userDao" ref="userDao"></property>
    </bean>

 

2.dispatch-servlet.xml

   <bean name="/login.do" class="cn.edgedu.web.LoginHandler">
        <property name="userService" ref="userService"></property>
        <property name="forwardInit">
            <value>/html/login.jsp</value>
        </property>
        <property name="forwardSucc" value="/html/main.jsp"></property>
        <property name="forwardFail" value="/html/login.jsp"></property>
    </bean>

 

3.web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <display-name>sprmvc</display-name>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>dispatch</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatch</servlet-name>
        <url-pattern>*.do</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>

 

代码文件:

1.index.jsp 页面

<!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>
<body>
    welcome!
    <a href="login.do?event=INIT">login</a>
</body>
</html>

 

报错信息:

当运行项目访问主页时,有如下报错(html的就好用,jsp就报错)

HTTP Status 500 - 

--------------------------------------------------------------------------------

type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: java.lang.NullPointerException
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:356)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause 

java.lang.NullPointerException
    org.apache.jsp.index_jsp._jspInit(index_jsp.java:22)
    org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:52)
    org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:159)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.18

 

 

郁闷好久了~~各种google也搞不定,求解答。。。谢谢!!


问题补充:
To :sunlightcs (资深程序员)
感谢回答,但是我现在还没运行任何业务,只是显示主页(见index.html页面)就抛500 ,好像是容器无法编译jsp页面呢。。。

3个回答

springMVC中没有配置viewResolver
参考SpringMVC指南中view和viewResolver章节

应该要有一个annomvc-servlet.xml类似这样的文件

class="org.springframework.web.servlet.view.InternalResourceViewResolver">
value="org.springframework.web.servlet.view.JstlView" />


你那哪是jsp页面,完整只是一个html页面而已嘛

最顶上加上

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!