【发布时间】:2018-05-25 01:58:51
【问题描述】:
我对 Java 和 Spring 还很陌生,并且在编写简单的应用程序时遇到了麻烦。
问题是,IntelliJ 看不到我在项目中的 .jsp 文件。该应用程序有效,但我没有从 IntelliJ 获得帮助。 我也无法将我在 homepage.jsp 中的 HomeController 类中创建的模型与表单和 modelAttribute 一起使用,因为它会变成红色并且不支持我编写代码。
.jsp 文件位于 webapp/WEB-INF/jsp/
我有 application.properties 文件:
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
这是我的文件:
HomeController.java
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HomeController {
@RequestMapping("/")
public String hello(Model theModel){
Credentials theCredentials = new Credentials();
theModel.addAttribute("credentials", theCredentials);
return "homepage";
}
}
凭据.java
public class Credentials {
private String username;
private String password;
public Credentials() {
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
主页.jsp
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Homepage</title>
</head>
<body>
Welcome to the virtual deanery!!!
<br><br>
Please log in as Student or Teacher to continue:
<br><br>
<form:form modelAttribute="credentials">
<%--credentials are not found--%>
<%--somecode--%>
</form:form>
</body>
</html>
非常感谢您的帮助!
【问题讨论】:
-
哪个 IntelliJ 版本?社区或终极社区。为此,您需要后者,它不适用于社区版。
-
我用的是2017.2终极版。
-
你解决过这个问题吗?我有完全相同的问题..
-
不幸的是,它似乎是某种错误......我的意思是它有效,但 IntelliJ 仍然表现得好像它不正确。
标签: java spring jsp spring-boot intellij-idea