我跟踪错误:
org.apache.jasper.JasperException:无法为JSP编译类:
An error occurred at line: 8 in the jsp file: /student/StudentError.jsp The method println6(String) is undefined for the type PrintStream 5: <p><b>Stack trace:</b></p> 6: <% 7: Exception exp = (Exception)request.getAttribute("javax.servlet.error.exception"); 8: System.out.println6(exp.getMessage()+"<br/>"); 9: StackTraceElement [] elements = exp.getStackTrace(); 10: for(int i=0;i<elements.length;i++){ 11: System.out.println(elements[i].toString()+"<br/>"); Stacktrace: at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103) at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:199) at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:446) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:361) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:336) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:323) at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:405) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:349) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:801) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:595) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1126) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1060) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:200) at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:75) at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209) at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267) at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1217) at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1005) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:952) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:801) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1126) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1060) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215) at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:113) at org.eclipse.jetty.server.Server.handle(Server.java:509) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:288) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:240) at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:539) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:620) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:540) at java.lang.Thread.run(Thread.java:745)
此处归档JavaClazzWeb-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd ">
<!-- <bean id="xsltViewResolver" class="org.springframework.web.servlet.view.xslt.XsltViewResolver">
<property name="order" value="1"/> <property name="viewClass" value ="org.springframework.web.servlet.view.xslt.XsltView"/>
<property name="sourceKey" value="data"/> <property name="suffix" value=".xsl"/>
<property name="prefix" value="/xsl/"/> </bean> <bean id="studentDAO" class="edu.java.spring.dao.StudentDAO">
<property name="dataSource" ref="dataSource"/> <property name ="insertSQL"
value="insert into student(name,age) values(?,?)"/> </bean> <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject"> <ref bean="studentDAO" /> </property> <property
name="targetMethod"> <value>createTableIfNotExist</value> </property> <property
name="arguments"> <list> <value>student</value> <value>create table student(
id bigint primary key generated always as identity(start with 1,increment
by 1), name varchar(1000), age integer ) </value> </list> </property> </bean> -->
<context:component-scan base-package="edu.java.spring.controller" />
<mvc:annotation-driven />
<mvc:resources location="/avatar/" mapping="/avatar/**" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="order" value="3" />
<property name="suffix" value=".jsp" />
<property name="prefix" value="/student/" />
</bean>
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="100000"></property>
</bean>
<bean id="xsltViewResolver"
class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
<property name="order" value="2" />
<property name="basename" value="views" />
</bean>
<bean id="tilesViewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="order" value="1" />
<property name="viewClass"
value="org.springframework.web.servlet.view.tiles3.TilesView" />
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles/definitions.xml</value>
</list>
</property>
</bean>
<bean id="studentDao" class="edu.java.spring.dao.impl.StudentHibernateDaoImpl" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.DerbyDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="packagesToScan" value="edu.java.spring.model" />
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="url"
value="jdbc:derby:D:\PROJECTSPRING\studentdb;create=true" />
<property name="username" value="" />
<property name="password" value="" />
</bean>
<bean
class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="java.lang.Exception">StudentError</prop>
</props>
</property>
</bean>
<bean id="studentMapper" class="edu.java.spring.model.StudentMapper" />
</beans>
这里是文件StudentController
@Controller
public class StudentController {
// @RequestMapping(value = "/student/add", method = RequestMethod.POST)
// public String addStudent(@Valid Student student,ModelMap model){
// model.addAttribute("name", student.getName());
// model.addAttribute("age", student.getAge());
// return "StudentView";
// }
@RequestMapping(value="/student/form",method = RequestMethod.GET )
public ModelAndView student(){
return new ModelAndView("StudentForm", "command", new Student());
}
@Autowired
public StudentHibernateDaoImpl studentDAO;
此处为文件类StudentHibernateDaoImpl
public class StudentHibernateDaoImpl implements StudentDAO {
@Autowired
public LocalSessionFactoryBean sessionFactory;
@Override
public void shutdown() {
// TODO Auto-generated method stub
}
@Override
public void insert(Student student) {
// TODO Auto-generated method stub
}
@Override
public List<Student> listStudents() {
// TODO Auto-generated method stub
Session session = sessionFactory.getObject().openSession();
Query query = (Query) session.createQuery("from Student");
try {
return (List<Student>)query.getResultList();
} finally {
// TODO: handle finally clause
session.close();
}
}
此处为文件类StudentDao
public interface StudentDAO {
public void shutdown();
public void insert(Student student);
public List<Student> listStudents();
public Student loadStudent(int id);
public void update(Student student);
public void delete(Integer id);
public List<Student> searchStudent(String name);
}
此处提交文件POM.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.java.spring</groupId>
<artifactId>springDAT-MVC</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>springDAT-MVC Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.0.1.Final</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.12.1.1</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.13</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>5.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.8.Final</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.0.5.RELEASE</version>
</dependency>
</dependencies>
<build>
<finalName>springDAT-MVC</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>true</skipTests>
<argLine>-Xmx2524m</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<fork>true</fork>
<compilerArgs>
<arg>-XDignore.symbol.file</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.0.M1</version>
<configuration>
<jvmArgs>-Xmx1048m -Xms536m
-XX:PermSize=128m -XX:MaxPermSize=512m</jvmArgs>
<reload>manual</reload>
<systemProperties>
<systemProperty>
<name>lib</name>
<value>${basedir}/target/spring-mvc/WEB-INF/lib</value>
</systemProperty>
</systemProperties>
<scanIntervalSeconds>3</scanIntervalSeconds>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<contextPath>/</contextPath>
<webAppSourceDirectory>${basedir}/src/main/webapp</webAppSourceDirectory>
<webXml>${basedir}/src/main/webapp/WEB-INF/web.xml</webXml>
<classesDirectory>${basedir}/target/classes</classesDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
此处提交学生
package edu.java.spring.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.Range;
@XmlRootElement(name="item")
@Entity
@Table(name = "student",uniqueConstraints={@UniqueConstraint(columnNames="Id")})
public class Student {
// @NotBlank
// @Size(min=2,max=100,message ="Age value is invalid")
private String name;
private int id;
// @Range(min=1,max=150)
private int age;
@XmlAttribute
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name ="id", unique=true,nullable =false)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@XmlElement
@Column(name = "Name",nullable = false,length = 200)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlElement
@Column(name = "age",nullable = false)
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
答案 0 :(得分:0)
回答您的问题
在您的情况下,您已使用@Repository注释标记DAOImpl类,如下所示。
@Repository
public class StudentHibernateDaoImpl实现StudentDAO {
将组件扫描标记更改为
<context:component-scan base-package="edu.java.spring.controller,yourPackage.StudentHibernateDaoImpl"/> >