Tag: spring mvc

如何在Spring MVC项目的“jsp”中使用“css”?

我正在开发一个spring MVC项目,我试图通过引用它来设计我的JSP页面来使用css样式表。 但不知何故,一旦我在控制器中按下我的方法,我的css文件就不会被拾取。 下面是我的JSP文件 – All header 1 elements will be red All header 2 elements will be blue All text in paragraphs will be green. 以下是我的test.css文件 – h1 {color:red;} h2 {color:blue;} p {color:green;} 以下是我在控制器类中的方法 – @RequestMapping(value = “testing”, method = RequestMethod.GET) public Map testing() { final Map model = new LinkedHashMap(); return model; } […]

如何在spring java配置中设置日志记录属性?

我正在使用Spring 5 MVC应用程序。 我试图获得纯Java配置。 我注意到我的日志记录无效。 我在我的application.properties中有这个: logging.level.org.springframework.web=ERROR logging.level.org.springframework.security=ERROR logging.level.org.hibernate.SQL=DEBUG logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE 现在我当然没有使用application.properties,那么如何在我的一个@Configuration类中以纯Java方式设置它?

使用自定义视图解析器和自定义视图的Spring MVC AJAX和JSON

自定义视图: public class MyView extends AbstractView { …. awesome stuff … } 控制器: @RequestMapping(value=”mylocation”) public ModelAndView dosomething() { … modelAndView.setView( new MyView() ); return modelAndView; } 由于某种原因,这不起作用…我唯一的视图解析器如下: spEnv 这段代码不起作用,因为它试图创建一些基于…的JSP视图。我不确定,我的表单提交路径; 显然没有JSP视图,我希望实际返回JSON,但由于某种原因这不起作用,它只是试图转发给我一些JSP,所以我猜我需要指定如何在我的XML中处理这个……但我已经看到人们返回JSON的大约1000种不同的方式,而且所有这些对我来说都很混乱,我只是寻找最简单的方法,所以我可以从那里 编辑:我添加了一个好的开始的答案,但它允许你在任何URL后键入“.json”,如果作为控制器我不会期待它会做一些非常糟糕的事情,所以我需要以某种方式此视图解析程序仅适用于安全URL

如何使用AJAX响应修改Spring mvc项目中的现有url?

我正在开发一个Spring MVC项目,其中主页有两个输入字段。 两个输入字段都是String类型。 但是regNo字段得到数字,如果用户输入regNo,它应该被带到控制器中的相应方法。 如果用户输入名称,则应将其转到控制器中的相应方法。 web.xml中 <!– Archetype Created Web Application –> contextConfigLocation /WEB-INF/spring/appContext.xml org.springframework.web.context.ContextLoaderListener dispatcher org.springframework.web.servlet.DispatcherServlet contextConfigLocation /WEB-INF/spring/dispatcher-servlet.xml 1 dispatcher /mvc/* /WEB-INF/jsp/template.jsp 1)id =“WebApp_ID”的目的是什么? tiles.xml 调度员servlet.xml中 <!– –> /WEB-INF/tiles.xml org.springframework.web.servlet.view.tiles2.TilesView ProjectController.java @Controller(“resultController”) public class ResultController { private final ResultService resultService; @Autowired public ResultController(ResultService resultService) { this.resultService = resultService; } @RequestMapping(value =”/template”, method = RequestMethod.GET) […]

org.hibernate.hql.internal.ast.QuerySyntaxException:意外令牌:*靠近第1行

我必须登录我的网站 Login 在控制器中我有 @RequestMapping(value=”/login”,method=RequestMethod.POST) public String loginUser(@RequestParam(“email”) String email, @RequestParam(“password”) String password,Model model,HttpSession session){ User persistedUser = userService.getUserByEmail(email); if(persistedUser!=null && persistedUser.getPassword().equals(password)){ session.setAttribute(“user”, persistedUser); return “home”; }else{ model.addAttribute(“error”, “Incorrect username or password, Please try again!”); return “login”; } } 在UserService中我将getUserByEmail()作为 public User getUserByEmail(String email) { return (User) em.createQuery(“SELECT * FROM User u WHERE u.email = :email”).setParameter(email, […]

如何将对象列表绑定到百万美元的复选框?

我在使用对象列表绑定复选框输入时遇到了很多困难。问题是当我在输入字段类型复选框上添加th:field =“* {userRole}”时 ,我在Web浏览器上收到错误请求作为响应。 这是我的代码: 用户模型类: public class User implements Serializable { private Integer id; private String username; private String password; private boolean enabled; private List userRole = new ArrayList(0); } UserRole Model类: public class UserRole implements Serializable { @Id @GeneratedValue private Integer userRoleId; @ManyToMany(mappedBy = “userRole”) private List users; @Column(name = “role”, nullable = […]

如何使用Spring 4 Rest Controller为Jsp视图服务?

我已经创建了Spring 4项目来构建rest服务。 所以我已经创建了超过50个rest服务,现在需要为此创建web-app。 所以我想重用相同的控制器,所以我只需要编写视图(JSP)代码。 为了同样我用Google搜索并找到了http://www.mkyong.com/spring-mvc/spring-3-mvc-contentnegotiatingviewresolver-example/,但这给了我一个错误。 Morover我的项目结构如下。 那么我需要在servlet-context.xml中编写这个配置? 实现的最佳方式是什么? 主要是我只需要输出Json和html。 所以它的我的http请求有一个扩展名.json和.jsp。 下面是我的一个控制器的代码。 下面是我创建Rest服务的方式,现在我希望这个方法与JSP页面的服务器相同。 package com.alumini.spring.controller; import java.util.ArrayList; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import com.alumini.spring.DAO.CourseDAO; import com.alumini.spring.model.Alumini; import com.alumini.spring.model.Course; @RestController public class CourseController { @Autowired private CourseDAO courseDao; @RequestMapping(value = “/getCourseList”) public List getCourseList(@RequestParam(“email”) String email,@RequestParam(“password”) String password) { List listCourse = […]

Spring MVC – 试图互相交互的2个不同的Web应用程序(安全性)

我们有2个不同的Web应用程序在同一个tomcat上运行。 webapp#1,webapp#2。 Webapp#1通过此服务方法连接到webapp#2: this.restTemplate.postForObject(url, request, responseType); webapp#2正在以下控制器中接收此请求: @RequestMapping(value = “/bla”, method = RequestMethod.POST) @ResponseStatus(value = HttpStatus.OK) @ResponseBody public ResponseDTO requestSomething(@RequestBody RequestDTO requestDTO, HttpServletRequest request) { return new ResponseDTO(“Hello”); } 现在,我们有一个安全要求,即我们在webapp#2中显示的这个控制器只接收来自webapp#1的请求。 实现这一目标有哪些替代方案? 我们是否必须从webapp#1在webapp#2中创建一个新会话? 如果是这样,凭证来自哪里? 我们应该就预定义的东西达成一 春季安全有没有办法解决这个问题? 谢谢!

Spring Security sec:使用Java Config授权标记

我目前正在开发一个用例,我需要使用以下Spring Security taglib来显示(或不显示)基于用户权限的链接。 在查看日志时,我发现在谈到日志时没有任何反应 无论我的角色如何,我总是看到按钮。 当我使用hasRole时,它可以工作,所以我肯定错过了的工作。 在阅读Spring Security参考的以下部分时: 要使用此标记,还必须在应用程序上下文中有一个WebInvocationPrivilegeEvaluator实例。 如果您使用命名空间,将自动注册。 …问题是该引用不包括Java Config。 所以我想我只需要在SecurityConfig类中定义一个@Bean ,就像这样: @Bean public WebInvocationPrivilegeEvaluator webInvocationPrivilegeEvaluator() { return new DefaultWebInvocationPrivilegeEvaluator(); } …但是,它需要一个FilterSecurityInterceptor实例,我已经在日志中看到了它。 事实上,它已经是我的filter链的一部分,所以我想知道如何在上面的DefaultWebInvocationPrivilegeEvaluator构造函数中引用它? Spring Security 3.2.4.RELEASE参考: http ://docs.spring.io/spring-security/site/docs/3.2.4.RELEASE/reference/htmlsingle/#the-authorize-tag 谢谢

Spring File Upload内部服务器错误

我正在尝试使用spring mvc上传文件。 我的表格: Name: Email ID: Attachment: Submit?: 我收到内部服务器错误。 错误是: 1)505错误 2)没有堆栈跟踪 表单重置自己而不是转到下一页,这是一个通知页面。