我是Java和Spring的新手,我在编写一个简单的应用程序时遇到了麻烦。
事实上,IntelliJ没有看到项目中的.jsp文件。应用程序有效,但我没有得到IntelliJ的帮助。 我也不能在我的homepage.jsp中使用forms和modelAttribute来使用我在HomeController类中创建的模型,因为它变成红色并且不支持我编写代码。
.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";
}
}
Credentials.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;
}
}
homepage.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>
非常感谢您的帮助!
答案 0 :(得分:0)
您的网络inf目录标记可能有问题。 右键单击webapp - &gt;将目录标记为 - &gt;来源根