的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>com.ssts</groupId>
<artifactId>momcab1</artifactId>
<name>momcab1</name>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>
<properties>
<java-version>1.7</java-version>
<org.springframework-version>4.0.3.RELEASE</org.springframework-version>
<org.aspectj-version>1.7.4</org.aspectj-version>
<org.slf4j-version>1.7.5</org.slf4j-version>
<hibernate.version>4.3.5.Final</hibernate.version>
<mysql.version>5.1.32</mysql.version>
<spring.security.version>3.2.5.RELEASE</spring.security.version>
<spring.batch.version>2.2.0.RELEASE</spring.batch.version>
</properties>
<dependencies>
<!--spring and hibernate validation -->
<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>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- Apache Commons DBCP -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<!-- Commons FileUpload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.1</version>
</dependency>
<!-- Spring ORM -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency>
<!-- @Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<!-- Java Mail Dependency -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1</version>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring.security.version}</version>
</dependency>
<!-- Spring Security JSP Taglib -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Spring new dependencies for Batch start-->
<!-- Spring Core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Spring Core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Spring Batch dependencies -->
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-core</artifactId>
<version>${spring.batch.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-infrastructure</artifactId>
<version>${spring.batch.version}</version>
</dependency>
<!-- Spring new dependencies for Batch end-->
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.test.int1.Main</mainClass>
</configuration>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>
</build>
</project>
momcab-servlet.xml中
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
">
<!-- DispatcherServlet Context: defines this servlet's request-processing
infrastructure -->
<context:component-scan base-package="com.ssts.momcab.controller" />
<!-- configuring the location of properties file -->
<context:property-placeholder location="classpath:Application.properties" />
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources
in the /WEB-INF/views directory -->
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<beans:bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes -->
<beans:property name="maxUploadSize" value="100000"/>
</beans:bean>
<!-- Here Defining required DB connectivity properties -->
<beans:bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="driverClassName" value="${database.driver}" />
<beans:property name="url" value="${database.url}" />
<beans:property name="username" value="${database.username}" />
<beans:property name="password" value="${database.password}" />
</beans:bean>
<!-- Hibernate 4 SessionFactory Bean definition -->
<beans:bean id="hibernate4AnnotatedSessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<beans:property name="dataSource" ref="dataSource" />
<beans:property name="annotatedClasses">
<beans:list>
<beans:value>com.ssts.momcab.model.Admin</beans:value>
<beans:value>com.ssts.momcab.model.Register</beans:value>
<beans:value>com.ssts.momcab.model.User</beans:value>
<beans:value>com.ssts.momcab.model.Booking</beans:value>
<beans:value>com.ssts.momcab.model.Chaffeur</beans:value>
<beans:value>com.ssts.momcab.model.Child</beans:value>
<beans:value>com.ssts.momcab.model.Driver</beans:value>
<beans:value>com.ssts.momcab.model.CustTransaction</beans:value>
<beans:value>com.ssts.momcab.model.ServiceRequest</beans:value>
<beans:value>com.ssts.momcab.model.Offer</beans:value>
<beans:value>com.ssts.momcab.model.MsgNotification</beans:value>
<beans:value>com.ssts.momcab.model.CustFeedback</beans:value>
<beans:value>com.ssts.momcab.model.BizLocation</beans:value>
<beans:value>com.ssts.momcab.model.LoggedinUser</beans:value>
<beans:value>com.ssts.momcab.model.UserBizLocMap</beans:value>
</beans:list>
</beans:property>
<!-- Here defining Hibernate required properties -->
<beans:property name="hibernateProperties">
<beans:props>
<beans:prop key="hibernate.dialect">${hibernate.dialect}
</beans:prop>
<beans:prop key="hibernate.show_sql">${hibernate.show_sql}
</beans:prop>
</beans:props>
</beans:property>
</beans:bean>
<beans:bean id="adminDAO" class="com.ssts.momcab.dao.AdminDAOImpl">
<beans:property name="sessionFactory"
ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
<beans:bean id="registerDAO" class="com.ssts.momcab.dao.RegisterDAOImpl">
<beans:property name="sessionFactory"
ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
<beans:bean id="userDAO" class="com.ssts.momcab.dao.UserDAOImpl">
<beans:property name="sessionFactory"
ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
<beans:bean id="adminService" class="com.ssts.momcab.service.AdminServiceImpl">
<beans:property name="adminDAO" ref="adminDAO"></beans:property>
</beans:bean>
<beans:bean id="registerService" class="com.ssts.momcab.service.RegisterServiceImpl">
<beans:property name="registerDAO" ref="registerDAO"></beans:property>
</beans:bean>
<beans:bean id="userService" class="com.ssts.momcab.service.UserServiceImpl">
<beans:property name="userDAO" ref="userDAO"></beans:property>
</beans:bean>
<beans:bean id="bookingDAO" class="com.ssts.momcab.dao.BookingDAOImpl">
<beans:property name="sessionFactory"
ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
<beans:bean id="bookingService" class="com.ssts.momcab.service.BookingServiceImpl">
<beans:property name="bookingDAO" ref="bookingDAO"></beans:property>
</beans:bean>
<beans:bean id="chaffeurDAO" class="com.ssts.momcab.dao.ChaffeurDAOImpl">
<beans:property name="sessionFactory"
ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
<beans:bean id="chaffeurService" class="com.ssts.momcab.service.ChaffeurServiceImpl">
<beans:property name="chaffeurDAO" ref="chaffeurDAO"></beans:property>
</beans:bean>
<beans:bean id="childDAO" class="com.ssts.momcab.dao.ChildDAOImpl">
<beans:property name="sessionFactory"
ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
<beans:bean id="childService" class="com.ssts.momcab.service.ChildServiceImpl">
<beans:property name="childDAO" ref="childDAO"></beans:property>
</beans:bean>
<beans:bean id="driverDAO" class="com.ssts.momcab.dao.DriverDAOImpl">
<beans:property name="sessionFactory"
ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
<beans:bean id="driverService" class="com.ssts.momcab.service.DriverServiceImpl">
<beans:property name="driverDAO" ref="driverDAO"></beans:property>
</beans:bean>
<beans:bean id="serviceRequestDAO" class="com.ssts.momcab.dao.ServiceRequestDaoImpl">
<beans:property name="sessionFactory"
ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
<beans:bean id="serviceRequestService"
class="com.ssts.momcab.service.ServiceRequestServiceImpl">
<beans:property name="serviceRequestDAO" ref="serviceRequestDAO"></beans:property>
</beans:bean>
<beans:bean id="custTransactionDAO" class="com.ssts.momcab.dao.CustTransactionDaoImpl">
<beans:property name="sessionFactory"
ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
<beans:bean id="custTransactionService"
class="com.ssts.momcab.service.CustTransactionServiceImpl">
<beans:property name="custTransactionDAO" ref="custTransactionDAO"></beans:property>
</beans:bean>
<beans:bean id="offerDAO" class="com.ssts.momcab.dao.OfferDAOImpl">
<beans:property name="sessionFactory"
ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
<beans:bean id="offerService" class="com.ssts.momcab.service.OfferServiceImpl">
<beans:property name="offerDAO" ref="offerDAO"></beans:property>
</beans:bean>
<beans:bean id="msgNotificationDAO" class="com.ssts.momcab.dao.MsgNotificationDaoImpl">
<beans:property name="sessionFactory"
ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
<beans:bean id="msgNotificationService"
class="com.ssts.momcab.service.MsgNotificationServiceImpl">
<beans:property name="msgNotificationDAO" ref="msgNotificationDAO" />
</beans:bean>
<beans:bean id="custFeedbackDAO" class="com.ssts.momcab.dao.CustFeedbackDaoImpl">
<beans:property name="sessionFactory"
ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
<beans:bean id="custFeedbackService"
class="com.ssts.momcab.service.CustFeedbackServiceImpl">
<beans:property name="custFeedbackDAO" ref="custFeedbackDAO"></beans:property>
</beans:bean>
<beans:bean id="bizLocationDAO" class="com.ssts.momcab.dao.BizLocationDAOImpl">
<beans:property name="sessionFactory"
ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
<beans:bean id="bizLocationService"
class="com.ssts.momcab.service.BizLocationServiceImpl">
<beans:property name="bizLocationDAO" ref="bizLocationDAO" />
</beans:bean>
<beans:bean id="loggedinUserDAO" class="com.ssts.momcab.dao.LoggedinUserDAOImpl">
<beans:property name="sessionFactory"
ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
<beans:bean id="loggedinUserService"
class="com.ssts.momcab.service.LoggedinUserServiceImpl">
<beans:property name="loggedinUserDAO" ref="loggedinUserDAO" />
</beans:bean>
<beans:bean id="userBizLocMapDAO" class="com.ssts.momcab.dao.UserBizLocMapDAOImpl">
<beans:property name="sessionFactory"
ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
<beans:bean id="userBizLocMapService"
class="com.ssts.momcab.service.UserBizLocMapServiceImpl">
<beans:property name="userBizLocMapDAO" ref="userBizLocMapDAO" />
</beans:bean>
<beans:bean id="pgService1" class="com.ssts.momcab.service.PGService1Impl">
</beans:bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<beans:bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<beans:property name="sessionFactory"
ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
</beans:beans>
Driver.jsp
<c:url var="addAction" value="/Drivers/add"></c:url>
<form:form action="${addAction}" enctype="multipart/form-data" commandName="driver">
<table width="400px" height="150px">
<tr>
<td><form:label path="name">
<spring:message text="Driver Name" />
</form:label></td>
<td><form:input path="name" /></td>
</tr>
<tr>
<td><form:label path="license">
<spring:message text="License Number" />
</form:label></td>
<td><form:input path="license" /></td>
</tr>
<tr>
<td><form:label path="password">
<spring:message text="Password" />
</form:label></td>
<td><form:input type="password" path="password" /></td>
</tr>
<tr>
<td><form:label path="address">
<spring:message text="Address" />
</form:label></td>
<td><form:input path="address" /></td>
</tr>
<tr>
<td><form:label path="number">
<spring:message text="Mobile Number" />
</form:label></td>
<td><form:input path="number" /></td>
</tr>
<tr>
<td><form:label path="blobImg">
<spring:message text="File" />
</form:label></td>
<td><form:input type="file" path="blobImg" /></td>
</tr>
<tr>
<td><input type="submit" value="<spring:message text="Submit"/>" /></td>
</tr>
</table>
</form:form>
DriverController.java
package com.ssts.momcab.controller;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import com.ssts.momcab.model.Admin;
import com.ssts.momcab.model.Driver;
import com.ssts.momcab.service.BookingService;
import com.ssts.momcab.service.DriverService;
import com.ssts.momcab.util.MomcabUtil;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
@Controller
public class DriverController {
@Value("${login_session_token_timeout_mnts}")
private String loginSessionTokenTimeoutMnts;
private DriverService driverService;
@Autowired(required = true)
@Qualifier(value = "driverService")
public void setDriverService(DriverService ds) {
this.driverService = ds;
}
@RequestMapping(value = "/Drivers", method = RequestMethod.GET)
public String Drivers(Model model,HttpServletRequest req,HttpServletResponse res) {
HttpSession session =req.getSession();
if(session.getAttribute("emailId")==null)
{
return "redirect:/login";
}
model.addAttribute("driver", new Driver());
return "driver";
}
@RequestMapping(value = "/Drivers/add", method = RequestMethod.POST)
public String Driver(@ModelAttribute("driver") Driver driver,@RequestParam("blobImg") MultipartFile blobImg) throws IOException {
if (driver.getId() == 0) {
// new user, add to DB
if (blobImg != null && !blobImg.isEmpty())
{
byte[] bytes = blobImg.getBytes();
driver.setBlobImg(bytes);
}
}
this.driverService.addDriver(driver);
return "redirect:/Drivers";
}
}
甚至我在pom.xml中添加了“commons-logging” 和momcab-servlet.xml中的“multipartResolver”的“bean”甚至没有在我的tomcat中运行。所以idk我的错误发生。感谢你的任何帮助。 谢谢你
答案 0 :(得分:1)
commons-fileupload
,但我没有添加commons-io
所以我添加了它们,我的问题就解决了
<!-- Apache Commons FileUpload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<!-- Apache Commons IO -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>