我的处理程序转发到internalresourceview“apiForm”,但是,然后我得到错误404 RequestURI = / WEB-INF /页/ apiForm.jsp。 我确定apiForm.jsp位于/ WEB-INF / pages / 13:45:02,034 DEBUG [org.springframework.web.servlet.view.JstlView] – 在InternalResourceView'apiForm'中转发资源[/WEB-INF/pages/apiForm.jsp] 13:45:02,035 DEBUG [org.springframework.web.servlet.DispatcherServlet] – 名为“testapp2”的DispatcherServlet确定[/WEB-INF/pages/apiForm.jsp]的Last-Modified值 13:45:02,038 DEBUG [org.springframework.web.servlet.DispatcherServlet] – 在getLastModified中找不到处理程序 13:45:02,038 DEBUG [org.springframework.web.servlet.DispatcherServlet] – 名为“testapp2”的DispatcherServlet处理[/WEB-INF/pages/apiForm.jsp] 13:45:02,038 WARN [org.springframework.web.servlet.PageNotFound] – 在名为“testapp2”的DispatcherServlet中找不到具有URI的HTTP请求的映射[/WEB-INF/pages/apiForm.jsp] 13:45:02,045 DEBUG [org.springframework.web.servlet.DispatcherServlet] – 成功完成请求 13:45:02,048 DEBUG [org.springframework.web.servlet.DispatcherServlet] – 成功完成请求 这是我的dispatcher.xml看起来像.. <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property […]
我正在使用jQuery的$.getJSON()asynchronous调用我的简单的Spring MVC后端。 大部分的Spring控制器方法如下所示: @RequestMapping(value = "/someURL", method = RequestMethod.POST) public @ResponseBody SomePOJO getSomeData(@ModelAttribute Widget widget, @RequestParam("type") String type) { return someDAO.getSomeData(widget, type); } 我已经设置了一些东西,以便每个控制器将@ResponseBody作为JSON返回,这正是客户端所期望的。 但是,当请求不应该返回任何内容到客户端时会发生什么? 我能有……吗: @RequestMapping(value = "/updateSomeData" method = RequestMethod.POST) public @ResponseBody void updateDataThatDoesntRequireClientToBeNotified(…) { … } 如果没有,在这里使用什么适当的语法? 提前致谢!
返回ModelAndView的方式 @RequestMapping(value = "/list", method = RequestMethod.GET) public ModelAndView list( @UserAuth UserAuth user, ModelAndView mav) { if (!user.isAuthenticated()) { mav.setViewName("redirect:http://www.test.com/login.jsp"); return mav; } mav.setViewName("list"); mav.addObject("articles", listService.getLists()); return mav; } 返回String的方式 @RequestMapping(value = "/list", method = RequestMethod.GET) public String list( @UserAuth UserAuth user, Model model) { if (!user.isAuthenticated()) { return "redirect:http://www.test.com/login.jsp"; } model.addAttribute("articles", listService.getLists()); return "list"; […]
我的Java Web应用程序提交返回JSON的AJAX请求,例如: {'value': 'aériennes'} 当“aériennes”显示在网页上时,它显示为“ariennes”,所以我猜这是一些字符编码问题。 AJAX响应头包括 Content-Type application/json 这似乎没有包含任何字符集信息。 我想这需要改变成类似的东西 Content-Type text/html; charset=iso-8859-1 (or charset=utf8) 应用程序的服务器端是Spring MVC,我想必须有一种方法来设置每个响应的默认字符集?
我试图做一些我认为应该很简单的事情。 我有一个Question对象,用spring-boot,spring-data-rest和spring-hateoas来设置。 所有的基本工作正常。 我想添加一个自定义控制器返回一个List<Question>与格式完全相同的格式,我的Repository的/questions URL做,以便两者之间的响应是兼容的。 这是我的控制器: @Controller public class QuestionListController { @Autowired private QuestionRepository questionRepository; @Autowired private PagedResourcesAssembler<Question> pagedResourcesAssembler; @Autowired private QuestionResourceAssembler questionResourceAssembler; @RequestMapping( value = "/api/questions/filter", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody PagedResources<QuestionResource> filter( @RequestParam(value = "filter", required = false) String filter, Pageable p) { // Using queryDSL here […]
我正在阅读Spring MVC的文档,我有一个关于init params的问题。 如果有问题,我正在使用Spring 3.2。 contextConfigLocation和名称空间有什么区别? contextConfigLocation仅用于指定上下文类可以findXML定义的文件夹,而namespace属性是用来指定文件名的? <servlet> <servlet-name>AppServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>WEB-INF</param-value> </init-param> <init-param> <param-name>namespace</param-name> <param-value>application-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> 它是否正确? 应该使用/WEB-INF/application-context.xml吗? 而且你应该指定path?
我的问题是如何configuration一个Spring MVC应用程序允许在同一时间 应用程序应该服务静态资源(CSS,JS,图像…) 根url( http://my.host.org/webb_app/ )应该由Spring控制器提供 我已经阅读了如何在Spring MVC中处理静态内容? , 使用Spring,映射到web.xml中的根目录,找不到 静态资源 , Tomcat为Spring MVC应用程序提供静态资源 。 所有提供的工作解决scheme,直到最近,我用它们作为烹饪食谱,直到应用程序工作或多或less可接受。 所有这些都没有提及,也没有清楚地理解为什么以及如何最终奏效。 所以问题是:为这个需求configuration一个Spring MVC应用程序的不同方式是什么,它们的缺点是什么,它们背后的基本原理是什么。
我有 @RequestMapping(method = RequestMethod.GET) @ResponseBody SessionInfo register(UserProfile profileJson){ … } 我以这种方式传递profileJson: http://server/url?profileJson={"email": "mymail@gmail.com"} 但我的profileJson对象具有所有的空字段。 我应该怎么做才能让springparsing我的json?
我正在使用Spring MVC。我必须编写一个服务,从请求主体获取input,将数据添加到pdf并将PDF文件返回给浏览器。 pdf文档是使用itextpdf生成的。 我怎样才能使用Spring MVC做到这一点。 我尝试过使用这个 @RequestMapping(value="/getpdf", method=RequestMethod.POST) public Document getPDF(HttpServletRequest request , HttpServletResponse response, @RequestBody String json) throws Exception { response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "attachment:filename=report.pdf"); OutputStream out = response.getOutputStream(); Document doc = PdfUtil.showHelp(emp); return doc; } 生成pdf的showhelp函数。 我只是暂时把一些随机数据放在pdf中。 public static Document showHelp(Employee emp) throws Exception { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("C:/tmp/report.pdf")); document.open(); document.add(new […]
我是Spring MVC框架的新手,我有一个我自己无法解决的问题。 一切都从我的应用程序集成Spring安全性开始,之后,所有来自HTML表单的unicode值都没有被编码(spring安全工作正常)。 我得出的结论是,这可能是因为我的DelegatingFilterProxy被称为链中的第一个filter。 这是我认为会起作用的configuration,但它不是: 1)我正在扩展AbstractSecurityWebApplicationInitializer – 从javadoc: Registers the DelegatingFilterProxy to use the springSecurityFilterChain() before any other registered Filter. 从那个类我也覆盖Spring关于javadoc的SpringSecurityFilterChain方法: Invoked before the springSecurityFilterChain is added. 所以我认为这将是注册CharacterEncodingFilter的最佳地点: public class MessageSecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer { @Override protected void beforeSpringSecurityFilterChain(ServletContext servletContext) { FilterRegistration.Dynamic characterEncodingFilter = servletContext.addFilter("encodingFilter", new CharacterEncodingFilter()); characterEncodingFilter.setInitParameter("encoding", "UTF-8"); characterEncodingFilter.setInitParameter("forceEncoding", "true"); characterEncodingFilter.addMappingForUrlPatterns(null, true, "/*"); } } […]