Java 无法编译我的第一个JSP程序
第二个jspJava 无法编译我的第一个JSP程序,java,jsp,Java,Jsp,第二个jsp <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <he
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form method=post action="Check.jsp">
<center><h3>Voter Application</h3></center>
Enter your Age:<input type="text" name="age">
<input type="submit" value = "Check Age">
</form>
</body>
错误如下:第二个JSP在else的大括号结尾处显示了一个编译错误。所有的java代码都在规则中,但我无法绕过这一条。在服务器上运行程序后,错误为HTTP状态500。无法为JSP编译类您在else行中缺少一个大括号。更改为:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<% int age = Integer.parseInt(request.getParametes(age));
if(age>=18){
%><h1>You are eligible to vote</h1>
<% else{ %> <h2>Sorry, you cant vote yet</h2>
<%} %>
</body>
</html>
</html>
永远不要使用Scriplet,而是使用更易于使用且不易出错的或 您可以使用或 更改:正确的版本1。request.getParameterage 2.}否则{ 致: 或 阅读更多关于 param:将请求参数名称映射到单个值
表达感谢的一个更好的方式是更新此响应并接受它作为答案。@BrianShowalter声誉为1的用户无法更新投票。yerp,can do it mate。值得接受。@BrianShowalter感谢您的答案。我想我们在课堂上还没有达到这一点。现在刚刚学习了scriplets。但是,是的,为提醒干杯
<% } else { %> <h2>Sorry, you cant vote yet</h2>
<% int age = Integer.parseInt(request.getParameter("age"));
if(age>=18){%>
<h1>You are eligible to vote</h1>
<%} else { %>
<h2>Sorry, you cant vote yet</h2>
<%} %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:choose>
<c:when test="${param.age>=18 }">
<h1>You are eligible to vote</h1>
</c:when>
<c:otherwise>
<h1>You are eligible to vote</h1>
</c:otherwise>
</c:choose>
<c:if test="${param.age>=18 }">
<h1>You are eligible to vote</h1>
</c:if>
<c:if test="${param.age<18 }">
<h1>Sorry, you cant vote yet</h1>
</c:if>