Tag: spring mvc

Thymeleaf没有显示弹簧控制器的值

我是第一次练习百里香模板引擎。 我已经按照教程等等,但我不知道我哪里出错了。 我的控制器: public String mainPage(Model model){ model.addAttribute(“data”, “Hello Thymeleaf”); return “main”; } 我的HTML如下: th:text=”${data}” 当我点击localhost时,它显示th:text =“$ {data}”而不是Hello Thymeleaf “${data}” 也不起作用。 查看解析程序配置必须正确,因为它将main解析为main.html。 我正在使用spring4 SpringTemplateEngine和spring4百万美元视图解析器。 提前致谢

Jsp页面给了我一个List,但是我的类想要一个Set

我有一个名为Menu的类,其中包含一个名为voceMenuList的字段,其中包含“Home”,“contact”等菜单项。 public class Menu implements Serializable{ private Set voceMenuList; public void setVoceMenuList(Set voceMenuList) { this.voceMenuList = voceMenuList;} public Set getVoceMenuList() { return voceMenuList;} } 这是我的jsp页面,我在输入文本中打印对象VoceMenu的字段,以便编辑该值 … URL … 当我发布页面时,我收到以下错误,可能是因为jsp页面返回一个List,但是我的类期望一个Set。 我该如何解决这个问题? 谢谢 org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.InvalidPropertyException: Invalid property ‘voceMenuList[0]’ of bean class [com.springgestioneerrori.model.Menu]: Getter for property ‘voceMenuList’ threw exception; nested exception is […]

@Valid没有触发 – Spring MVC 3.2

出于某种原因,它不起作用。 我搜索并尝试了在网上找到的所有解决方案。 没有骰子。 看起来我错过了什么。 我的光束: @Entity @Table(name=”employees”) public class Person { private Integer person_id; private String name; private String name2; private String email; private double phone; private String desc; @Id @Max(value=500) @Column (name=”id”) public Integer getPerson_id() { return person_id; } public void setPerson_id(Integer person_id) { this.person_id = person_id; } @NotNull @NotEmpty @Column (name=”fn”) public String […]

Java Web应用程序安全性:向请求添加令牌

我正在寻找一种方法或当前的API,允许您将令牌添加到Web应用程序请求。 也许在会议期间但不是坚持。 或者,如果您可以通过概述一种有效的方法来帮助我 例如 1. GET request => Servlet生成一个令牌并在视图中打印它 2.返回带有隐藏令牌的视图 3.提交POST请求=>表单并检查令牌是否相同。 很少有事情需要注意,如果有Ajax请求,那么其他一些令牌必须在许多请求中处于活动状态。 如果用户决定关闭浏览器,则当会话超时时,令牌将不得不死亡。 如果用户未能完成表单,则在网站上执行其他操作,则必须在未使用时删除这些令牌。 但实现这样的系统的最佳方法是什么, Spring Security 3有一个我可以使用的系统吗? 在Java,Grails,Spring MVC,Spring Security 3和Hibernate领域

处理Spring中的404错误?

这是我将未映射的请求重定向到404页面的代码 @RequestMapping(“/**”) public ModelAndView redirect() { ModelAndView mv = new ModelAndView(); mv.setViewName(“errorPage”); return mv; } 上面的代码工作正常,但问题是像css和js文件这样的web资源也进入这个重定向方法,并且它没有加载任何文件。 但我已经在我的调度程序servlet中有这个代码,但是spring控制器没有识别这个资源映射。 所以我在请求映射中尝试了一些正则表达式来否定资源url这样的东西 @RequestMapping(“/{^(?!.*resources/**)}**”) public ModelAndView redirect() { ModelAndView mv = new ModelAndView(); mv.setViewName(“errorPage”); return mv; } 但这并没有按预期工作。所以,如果有人能帮助它会很棒:)

从文件系统导入eclipse项目,然后在服务器上运行

我想在这个链接上做春季安全教程。 在标题为“运行没有Spring Security的教程应用程序”的部分中 ,我采取了以下步骤(针对当前版本与编写教程时使用的版本之间的差异进行了调整): 1.) I downloaded the latest release of the Spring Security Distribution, 2.) found and unzipped a war file in the dist directory called spring-security-samples-tutorial-3.1.2.RELEASE.war 3.) Renamed the resulting folder spring-security-tutorial 4.) Created a general project in eclipse called spring-security-tutorial 5.) Imported all of the contents of the unzipped spring-security-samples-tutorial-3.1.2.RELEASE.war 6.) Right […]

SpringDataRest并显示welcome-file-list / disable链接发现

我在spring-mvc应用程序中使用spring-data-rest(1.0.0.RELEASE)但是我遇到了以下问题 在我的WebConfig中 @Import(RepositoryRestMvcConfiguration.class) public static class WebConfiguration extends WebMvcConfigurationSupport{…} 在这种情况下, RepositoryRestMvcConfiguration有一个bean RepositoryRestController ,它有方法listRepositories(…)注释 @RequestMapping(value = “/”, method = RequestMethod.GET) 现在的问题是,当我在根上下文(“/”)点击时,我得到了我的存储库的链接,如下所示 { “links” : [ { “rel” : “content”, “href” : “http://localhost:7070/appName/content” }, { “rel” : “language”, “href” : “http://localhost:7070/appName/language” } ], “content” : [ ] } 但我想显示index.html文件。 我想在根上下文中禁用链接的发现。 事件我尝试使用我的自定义控制器映射到根上下文(“/”)但是第一优先级的spring与RepositoryRestController’s.listRepositories(…)方法匹配。 它不会出现在我的控制器方法中。 在日志中,它就像这样 **RepositoryRestHandlerMapping**: 185 – Mapped […]

Spring框架 – GET和POST之间的区别

我正在使用Spring Framework在JSP上开发一个网页,我知道GET和POST之间的区别,如果页面发送了POST动作; 在浏览器区域,似乎没有发送信息,而在GET中则恰恰相反。 在Spring框架中,我通过控制器发送和获取信息,在编写控制器之前,我使用Request映射; @RequestMapping(value = “/pri/SuperUser/ResetPassword.qib”,method = RequestMethod.GET) @Override public ModelandView function(Model model){ … … 那么,在这种情况下使用GET和POST有什么区别。 除了在浏览器字段中看到发送的信息之外,应该有其他不同之处。

Spring MVC返回自定义HTTP状态代码(无错误)

在Spring MVC @RequestMapping注释中,我返回JSP页面名称作为结果。 这将返回HTTP状态代码200 OK。 如何将此状态代码更改为201创建的内容? @ResponseStatus不起作用。 此外,HttpServletResponse将无法工作,因为我只需要返回我的自定义JSP页面。 @RequestMapping(method = RequestMethod.POST) public String addPhone(@ModelAttribute(“phone”) Phone phoneVO) { phoneManager.addPhone(phoneVO); return “redirect:/phone”; }

Spring 3.1.2使用@ResponseBody的MVC @ExceptionHandler

我正在尝试使用@ResponseBody实现Spring Web MVC @ExceptionHandler以返回包含validation错误的对象。 ( 策略E记录在这里 )。 在Spring 3.0.x中,有一个确认的错误 ,因为已经解决,禁止它正常工作。 我正在使用Spring 3.1.2,不应该遇到那个。 但是,我遇到了一个例外情况“无法找到可接受的代表”。 这是例外: [10/21/12 12:56:53:296 CDT] 00000045 ExceptionHand E redacted.loggi ng.jdk14.LogWrapper error Failed to invoke @ExceptionHandler method: public redacted.model.view.ValidationErrorResponse redacted.controller.Re stController.handleValidationException(redacted.util.ValidationExceptio n,javax.servlet.http.HttpServletResponse) Originating Class/Method:redacted.web.ui.filter.AccessControlFilter.pr ocessFilter() org.springframework.web.HttpMediaTypeNotAccepta bleException: Could not find acceptable representation at org.springframework.web.servlet.mvc.method.annotation.AbstractMessage ConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMeth odProcessor.java:115) 这是代码: @ExceptionHandler(ValidationException.class) @ResponseStatus(value = HttpStatus.PRECONDITION_FAILED) @ResponseBody public ValidationErrorResponse […]