我这样为什么不对,请老师帮我看看 谢谢
来源:2-8 自由编程
qq_慕移动0378797
2019-11-19 20:33:42
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="http://localhost/jstl/p">
<input type="text" name="num" >
<input type="submit" value="提交">
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
${requestScope.x};
<c:if test="${0<x}" && test="${x<=10}">
<h1 style="color=bule">1-10之间的整数</h1>
</c:if>
<c:if test="${x>10}"&&test="${x<=20}">
<h1 style="color=bule">11-20之间的整数</h1>
</c:if>
<c:otherwise>
<h1 style="color=red">数字超过想验证范围</h1>
</c:otherwise>
</body>
</html>
package com.imooc.jstl;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.catalina.startup.SetAllPropertiesRule;
/**
* Servlet implementation class p
*/
@WebServlet("/p")
public class p extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public p() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String num=request.getParameter("num");
int a=Integer.parseInt(num);
request.setAttribute("x", a);
request.getRequestDispatcher("/judeg.jsp").forward(request, response);
}
}1回答
同学你好,1、在使用c:if标签时,test属性的书写形式如下:

2、单分支判断,不可以与<c:otherwise>一起使用,程序会报错的

建议去掉<c:otherwise>标签以及其中的内容。
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
相似问题