Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //download resume
- //----------------------------------------------------------------------
- @RequestMapping(value="/download/{fileName.+}",method=RequestMethod.GET)
- public void downloadPDFResource(HttpServletRequest request,
- HttpServletResponse response,@PathVariable("fileName") String fileName){
- System.out.println("filename i got :"+fileName);
- //If user is not authorized - he should be thrown out from here itself
- //String fileName="Ente Kadha - Madhavikkutty.pdf";
- //Authorized user will download the file
- String dataDirectory = request.getServletContext().getRealPath("/WEB-INF/downloads/");
- Path file = Paths.get(dataDirectory, fileName);
- if (Files.exists(file)) {
- response.setContentType("application/pdf");
- response.addHeader("Content-Disposition", "attachment; filename=" + fileName);
- try {
- Files.copy(file, response.getOutputStream());
- response.getOutputStream().flush();
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- else
- {
- System.out.println("nnFile not found!!nn");
- System.out.println(file);
- }
- }
- <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
- <%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Profile</title>
- </head>
- <body>
- <table>
- <th><h3>${profile.name}</h3></th>
- <tr>
- <td>Application Id :</td>
- <td>${profile.a_id}</td>
- </tr>
- <tr>
- <td>Name :</td>
- <td>${profile.name}</td>
- </tr>
- <tr>
- <td>Address :</td>
- <td>${profile.address}</td>
- </tr>
- <tr>
- <td>Email:</td>
- <td>${profile.email}</td>
- </tr>
- <tr>
- <td>Phone:</td>
- <td>${profile.phone}</td>
- </tr>
- <tr>
- <td>Vacancy id:</td>
- <td></td>
- </tr>
- <tr>
- <td>Date Applied :</td>
- <td>${profile.dateApplied}</td>
- </tr>
- <tr>
- <td>Resume : ${profile.resumePath}${profile.resumeDoc} </td>
- <td><a href="download/${profile.resumeDoc}">Download ${profile.resumeDoc}</a></td>
- </tr>
- </table>
- </body>
- </html>
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:p="http://www.springframework.org/schema/p"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.0.xsd">
- <context:component-scan base-package="controller"></context:component-scan>
- <context:component-scan base-package="DAO"></context:component-scan>
- <!--<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>-->
- <!--
- Most controllers will use the ControllerClassNameHandlerMapping above, but
- for the index controller we are using ParameterizableViewController, so we must
- define an explicit mapping for it.
- -->
- <!--<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
- <property name="mappings">
- <props>
- <prop key="index.htm">indexController</prop>
- </props>
- </property>
- </bean>-->
- <bean id="viewResolver"
- class="org.springframework.web.servlet.view.InternalResourceViewResolver"
- p:prefix="/WEB-INF/jsp/"
- p:suffix=".jsp" />
- <bean id="multipartResolver"
- class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
- <bean id="con" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
- <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
- <property name="url" value="//my url"></property>
- <property name="username" value="root"></property>
- <property name="password" value="root"></property>
- <!--
- //for ms sql server,it may be like :
- database-driver=net.sourceforge.jtds.jdbc.Driver
- url=jdbc:jtds:sqlserver://localhost:1433/simplehr;instance=SQLEXPRESS
- username=shoppingcart
- password=12345
- -->
- </bean>
- <!-- normal jdbc template bean-->
- <bean id="template" class="org.springframework.jdbc.core.JdbcTemplate">
- <property name="dataSource" ref="con"></property>
- </bean>
- <!-- this bean uses normal jdbc template -->
- <bean id="contactsDAO" class="DAO.ContactsDAO">
- <property name="jdbc" ref="template"></property>
- </bean>
- <!-- this bean uses normal jdbc template -->
- <bean id="vacancyDAO" class="DAO.VacancyDAO">
- <property name="jdbc1" ref="template"></property>
- </bean>
- <!-- this bean uses normal jdbc template -->
- <bean id="careerDAO" class="DAO.CareerDAO">
- <property name="jdbc2" ref="template"></property>
- </bean>
- </beans>
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
- <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>dispatcher</servlet-name>
- <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
- <load-on-startup>2</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>dispatcher</servlet-name>
- <url-pattern>/</url-pattern>
- </servlet-mapping>
- <session-config>
- <session-timeout>
- 30
- </session-timeout>
- </session-config>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- </web-app>
- WARNING [http-nio-8084-exec-129] org.springframework.web.servlet.DispatcherServlet.noHandlerFound No mapping found for HTTP request with URI [/IntelliLabsWeb/oneProfile/download/Ente Kadha - Madhavikkutty.pdf] in DispatcherServlet with name 'dispatcher'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement