Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.67 KB | None | 0 0
  1. //download resume
  2. //----------------------------------------------------------------------
  3. @RequestMapping(value="/download/{fileName.+}",method=RequestMethod.GET)
  4. public void downloadPDFResource(HttpServletRequest request,
  5. HttpServletResponse response,@PathVariable("fileName") String fileName){
  6.  
  7.  
  8. System.out.println("filename i got :"+fileName);
  9. //If user is not authorized - he should be thrown out from here itself
  10.  
  11. //String fileName="Ente Kadha - Madhavikkutty.pdf";
  12.  
  13. //Authorized user will download the file
  14. String dataDirectory = request.getServletContext().getRealPath("/WEB-INF/downloads/");
  15. Path file = Paths.get(dataDirectory, fileName);
  16. if (Files.exists(file)) {
  17. response.setContentType("application/pdf");
  18. response.addHeader("Content-Disposition", "attachment; filename=" + fileName);
  19. try {
  20. Files.copy(file, response.getOutputStream());
  21. response.getOutputStream().flush();
  22. } catch (IOException ex) {
  23. ex.printStackTrace();
  24. }
  25. }
  26. else
  27. {
  28. System.out.println("nnFile not found!!nn");
  29. System.out.println(file);
  30. }
  31. }
  32.  
  33. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  34. <%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
  35. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  36. <!DOCTYPE html>
  37. <html>
  38. <head>
  39. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  40. <title>Profile</title>
  41. </head>
  42. <body>
  43.  
  44. <table>
  45.  
  46. <th><h3>${profile.name}</h3></th>
  47. <tr>
  48. <td>Application Id :</td>
  49. <td>${profile.a_id}</td>
  50. </tr>
  51. <tr>
  52. <td>Name :</td>
  53. <td>${profile.name}</td>
  54. </tr>
  55. <tr>
  56. <td>Address :</td>
  57. <td>${profile.address}</td>
  58. </tr>
  59. <tr>
  60. <td>Email:</td>
  61. <td>${profile.email}</td>
  62. </tr>
  63. <tr>
  64. <td>Phone:</td>
  65. <td>${profile.phone}</td>
  66. </tr>
  67. <tr>
  68. <td>Vacancy id:</td>
  69. <td></td>
  70. </tr>
  71. <tr>
  72. <td>Date Applied :</td>
  73. <td>${profile.dateApplied}</td>
  74. </tr>
  75. <tr>
  76. <td>Resume : ${profile.resumePath}${profile.resumeDoc} </td>
  77. <td><a href="download/${profile.resumeDoc}">Download ${profile.resumeDoc}</a></td>
  78. </tr>
  79.  
  80. </table>
  81.  
  82. </body>
  83. </html>
  84.  
  85. <?xml version="1.0" encoding="UTF-8"?>
  86. <beans xmlns="http://www.springframework.org/schema/beans"
  87. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  88. xmlns:p="http://www.springframework.org/schema/p"
  89. xmlns:context="http://www.springframework.org/schema/context"
  90. xsi:schemaLocation="http://www.springframework.org/schema/beans
  91. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  92. http://www.springframework.org/schema/context
  93. http://www.springframework.org/schema/context/spring-context-3.0.xsd">
  94.  
  95. <context:component-scan base-package="controller"></context:component-scan>
  96. <context:component-scan base-package="DAO"></context:component-scan>
  97.  
  98. <!--<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>-->
  99.  
  100. <!--
  101. Most controllers will use the ControllerClassNameHandlerMapping above, but
  102. for the index controller we are using ParameterizableViewController, so we must
  103. define an explicit mapping for it.
  104. -->
  105. <!--<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
  106. <property name="mappings">
  107. <props>
  108. <prop key="index.htm">indexController</prop>
  109. </props>
  110. </property>
  111. </bean>-->
  112.  
  113. <bean id="viewResolver"
  114. class="org.springframework.web.servlet.view.InternalResourceViewResolver"
  115. p:prefix="/WEB-INF/jsp/"
  116. p:suffix=".jsp" />
  117.  
  118. <bean id="multipartResolver"
  119. class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
  120.  
  121. <bean id="con" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  122. <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
  123. <property name="url" value="//my url"></property>
  124. <property name="username" value="root"></property>
  125. <property name="password" value="root"></property>
  126.  
  127. <!--
  128. //for ms sql server,it may be like :
  129. database-driver=net.sourceforge.jtds.jdbc.Driver
  130. url=jdbc:jtds:sqlserver://localhost:1433/simplehr;instance=SQLEXPRESS
  131. username=shoppingcart
  132. password=12345
  133. -->
  134. </bean>
  135.  
  136. <!-- normal jdbc template bean-->
  137. <bean id="template" class="org.springframework.jdbc.core.JdbcTemplate">
  138. <property name="dataSource" ref="con"></property>
  139. </bean>
  140.  
  141.  
  142. <!-- this bean uses normal jdbc template -->
  143. <bean id="contactsDAO" class="DAO.ContactsDAO">
  144. <property name="jdbc" ref="template"></property>
  145. </bean>
  146.  
  147. <!-- this bean uses normal jdbc template -->
  148. <bean id="vacancyDAO" class="DAO.VacancyDAO">
  149. <property name="jdbc1" ref="template"></property>
  150. </bean>
  151.  
  152. <!-- this bean uses normal jdbc template -->
  153. <bean id="careerDAO" class="DAO.CareerDAO">
  154. <property name="jdbc2" ref="template"></property>
  155. </bean>
  156.  
  157. </beans>
  158.  
  159. <?xml version="1.0" encoding="UTF-8"?>
  160. <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">
  161. <context-param>
  162. <param-name>contextConfigLocation</param-name>
  163. <param-value>/WEB-INF/applicationContext.xml</param-value>
  164. </context-param>
  165. <listener>
  166. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  167. </listener>
  168. <servlet>
  169. <servlet-name>dispatcher</servlet-name>
  170. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  171. <load-on-startup>2</load-on-startup>
  172. </servlet>
  173. <servlet-mapping>
  174. <servlet-name>dispatcher</servlet-name>
  175. <url-pattern>/</url-pattern>
  176. </servlet-mapping>
  177. <session-config>
  178. <session-timeout>
  179. 30
  180. </session-timeout>
  181. </session-config>
  182. <welcome-file-list>
  183. <welcome-file>index.jsp</welcome-file>
  184. </welcome-file-list>
  185. </web-app>
  186.  
  187. 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