我有一个下一个代码jsp
文件:
<%--
Created by IntelliJ IDEA.
User: __it
Date: 08.04.2019
Time: 14:00
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Student Confirmation</title>
</head>
<body>
The stuent is confirmed: ${student.firstName} ${student.lastName}
<br><br>
Country: ${student.country}
<br><br>
Favourite language: ${student.favLnguage}
<br><br>
Operating system(s):
<ul>
<c:forEach var="temp" items="${student.operatingSystems}">
<li>${temp}"</li>
</c:forEach>
</ul>
</body>
</html>
在第31行,我尝试遍历operatingSystem
数组。
在学生课堂上,它看起来像:
private String[] operatingSystems;
当我运行服务器时,在选择operatingSystems
之后,我会得到下一个结果:
如您所见,迭代在浏览器中不起作用,但是从思想上讲,我已经拥有了自己的操作系统。我发出声音以确保选择操作系统后不会返回null。
我的选择框:
<p> Operating systems </p>
Linux <form:checkbox path="operatingSystems" value="Linux"/>
Mac OS <form:checkbox path="operatingSystems" value="MacOS"/>
Windows <form:checkbox path="operatingSystems" value="Wimdows OS"/>
我的Pom XML:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.spring</groupId>
<artifactId>SpringgMVC</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>10</source>
<target>10</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.1.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.1.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>LATEST</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.6.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jsp-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
</dependencies>
</project>
答案 0 :(得分:0)
我在上面的注释中看到错误的输入(我在URL上没有看到 http:// )。尽管这可能是偶然完成的。 无论如何,尝试将其替换为此:
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
对于支持jstl
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
答案 1 :(得分:0)
我仍然不能使用<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
,但是我在jsp文件中使用了迭代。
Operating system(s):
<table>
<% String[] system = (String[]) request.getAttribute("os");
for (int i = 0; i < system.length; i++) {
String os = system[i];
%>
<tr>
<td><%out.print(os);%></td>
</tr>
<%}%>
</table>
在控制器类中,我必须创建一个数组,然后setAttribute("array", array);
是的,这是硬代码,但这是我建立的唯一一个决定。