我跟踪错误:
空
edu.java.spring.controller.StudentController.listStudents(StudentController.java:86)
sun.reflect.NativeMethodAccessorImpl.invoke0(原生方法)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:497)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:801)
org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1126)
org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1060)
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)
org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:113)
org.eclipse.jetty.server.Server.handle(Server.java:509)
org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:288)
org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:240)
org.eclipse.jetty.io.AbstractConnection $ 2.run(AbstractConnection.java:539)
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:620)
org.eclipse.jetty.util.thread.QueuedThreadPool $ 3.run(QueuedThreadPool.java:540)
java.lang.Thread.run(Thread.java:745)
null
此处归档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)
显然,问题是这个字符串
System.out.println6(exp.getMessage()+"<br/>");
您应该使用System.out.println
,而不是System.out.println6
System.out.println(exp.getMessage()+"<br/>");