Tag: spring mvc

在Spring MVC中写入文件请求

我希望能够将整个请求写入Spring MVC控制器中的文件。 我尝试了以下内容,但即使我正在使用大量参数发出POST请求,该文件也始终为空: @RequestMapping(method = RequestMethod.POST, value = “/payments/confirm”) public void receiveCallback(ServletInputStream inputStream) { try { inputStream.reset(); byte[] data = IOUtils.toByteArray(inputStream); File file = new File(System.getProperty(“java.io.tmpdir”) + “test” + System.currentTimeMillis() + “.txt”); FileOutputStream fos = new FileOutputStream(file); fos.write(data); fos.close(); } catch (Exception e) { logger.error(“Error writing request”, e); } } 我也尝试过使用HttpServletRequest.getInputStream(),但结果相同。

如何使用Spring MVC JSR-303 Validator将不同的模型类validation为一个表单

我在jsp页面中有表格如下: First Name Last Name Email Street City State Country 在这个jsp名字,姓氏和电子邮件属于一个模型类,即员工。 最后所有属性如Street,City等属于EmployeeDetails模型类。 public class Employee { private Long empId; @Size(min=2, max=30) private String firstName; @Size(min=2, max=30) private String lastName; @NotEmpty @Email private String email; @DateTimeFormat(pattern=”MM/dd/yyyy”) @NotNull @Past private Date doj; @Phone private String phone; private EmployeeDetail employeeDetail; Getter/Setter } EmployeeDetail: public class EmployeeDetail { @Size(min=2, […]

在tomcat 8的共享文件夹中添加属性文件,并在Spring MVC Web应用程序中使用它

我有一个Java Spring MVC Web应用程序。 我使用application.properties文件来设置一些属性值。 现在我试图让属性独立于war文件。 我在tomcat下创建了一个新的文件夹shared / classes,如下所示。 在catalina.properties文件中,我添加了shared.loader=${catalina.base}/shared/classes 。 在我的root-context.xml文件中,我添加了 但我收到以下错误: ERROR osweb.context.ContextLoader – Context initialization failed org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: E:\projects\smartwcm\workspace-20163101-eclipse-wp\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\shared\classes\application.properties (The system cannot find the path specified) 我该如何解决这个问题?

Eclipse:错误启动静态资源java.lang.IllegalArgumentException

我的Eclipse IDE中有一个名为myproject2的项目。 我有一个Tomcat应用程序服务器,我可以在那里添加资源myproject2(它是一个Spring MVC项目)。 现在我关闭了Eclipse中的myproject2,从Tomcat资源中删除了myproject2并使用projectname:myproject3进行了新的Subversion结帐。 重新启动IDE我想将myproject3设置为Tomcat服务器,因此应该部署它。 但所有可用的是myproject2可供选择。 所以我选择它。 我可以访问http:// localhost:8080 / myproject2 /但是我收到此警告并在控制台中提供: 14.12.2010 11:43:11 org.apache.catalina.startup.HostConfig deployDescriptor WARNING: A docBase C:\Spring\apache-tomcat-6.0.29-windows-x86\apache-tomcat-6.0.29\webapps\myproject2 inside the host appBase has been specified, and will be ignored 14.12.2010 11:43:11 org.apache.catalina.core.StandardContext resourcesStart SERVE: Error starting static Resources java.lang.IllegalArgumentException: Document base C:\Spring\apache-tomcat-6.0.29-windows-x86\apache-tomcat-6.0.29\webapps\myproject3 does not exist or is not a readable directory at […]

什么是spring MVC中的调试日志记录

我的春季MVC无法正常工作,我找不到错误资源。 我听说过调试日志。 这是我可以打开的东西,我可以看到更多细节,问题在哪里或 是我需要在每个文件中编程的东西,只显示我在文件中硬编码的消息

尝试上传时无效的CSRF令牌Spring 4 MVC

我试图使用Spring MVC 4上传一个带有Web应用程序的文件,但是我收到一个错误: 在请求参数’_csrf’或标题’X-CSRF-TOKEN’上找到无效的CSRF令牌’null’。 春季版: Spring Version 4.1.7.RELEASE Spring Security 4.0.1.RELEASE 码: web.xml中 FATCA Web Application contextConfigLocation /WEB-INF/spring-web-servlet.xml spring-web org.springframework.web.servlet.DispatcherServlet 1 spring-web *.html 弹簧网络servlet.xml中 /WEB-INF/views/ .jsp Settings.jsp <input type="submit" value= /> 在提交包含字符串“Test”的名为test.txt的文件后发布请求有效内容: Content-Type: multipart/form-data; boundary=—————————83935555814334632461054528816 Content-Length: 368 —————————–83935555814334632461054528816 Content-Disposition: form-data; name=”file”; filename=”test.txt” Content-Type: text/plain Test —————————–83935555814334632461054528816 Content-Disposition: form-data; name=”_csrf” 41f3dc0a-b97f-4dac-bc49-21e02be53818 —————————–83935555814334632461054528816–

Spring Data Pagination在JSONView中没有返回任何结果

我在我的REST控制器中使用Spring数据分页并返回Paged实体。 我想在JSONViews的帮助下控制作为JSON返回的数据。 当我返回一个对象时,我能够实现结果。 但是当我返回Page时,我收到空白的JSON作为回复。 以下是我的方法签名。 @JsonView(TravelRequestView.MyRequests.class) @RequestMapping(“/travel/requests”) public Page getUserTravelRequests( @RequestParam(“ps”) int pageSize, @RequestParam(“p”) int page, @RequestParam(defaultValue = “”, value = “q”) String searchString) 我删除@JsonView注释时能够收到响应。

SpringMVC和Hibernate:CannotCreateTransactionException:无法打开Hibernate Session进行事务处理;

我正在尝试设置和Spring MVC + Hibernate项目,但它让我疯狂。 我还会考虑建议订购xml配置文件。 我有以下文件: web.xml contextConfigLocation /WEB-INF/spring/root-context.xml org.springframework.web.context.ContextLoaderListener appServlet org.springframework.web.servlet.DispatcherServlet contextConfigLocation /WEB-INF/spring/appServlet/servlet-context.xml 1 appServlet / servlet-context.xml classpath:hibernate.cfg.xml org.hibernate.dialect.SQLServer2008Dialect true PersonController.java package es.landesoft.mvctesting; import java.util.List; import java.util.Locale; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; 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.bind.annotation.ResponseBody; import es.landesoft.mvctesting.JavaBeans.Person; import es.landesoft.mvctesting.service.PersonService; /** * Handles requests for […]

Spring MVC控制器inheritanceSpring安全性

我正在尝试使用spring mvc 3.2.3和spring security 3.1.3创建一个通用控制器。 我想要实现的是这样的: public abstract class DataController { protected abstract E getEntity(String id); @RequestMapping(value=”/view/{id}”, method=RequestMethod.GET) public String view(@PathVariable(“id”) String id, ModelMap map) { E ent = getEntity(id); map.put(“entity”, entity); return “showEntity”; } } 我的扩展类将在类名中有一个特定的控制器映射,以便我可以使用控制器名称访问该URL: @Controller @RequestMapping(“/company**”) @Secured(“ROLE_ADMIN”) public class CompaniesController extends DataController { @Autowired private AppService appService; @Override protected Company getEntity(String id) […]

Java Spring MVC在浏览器中显示PDF

如何强制浏览器显示pdf而不是下载? 这是控制器 @RequestMapping(value = “/preview.pdf”, method = RequestMethod.GET) protected String preivewSection( HttpServletRequest request, HttpSession httpSession, HttpServletResponse response) { try { byte[] documentInBytes = getDocument(); response.setHeader(“Content-Disposition”, “inline; filename=\”report.pdf\””); response.setDateHeader(“Expires”, -1); response.setContentType(“application/pdf”); response.setContentLength(documentInBytes.length); response.getOutputStream().write(documentInBytes); } catch (Exception ioe) { } finally { } return null; }