JSP界面传值,跳转,调用JS函数

06. February 2017 笔记 0

lijian.jsp

<%@page import=”java.util.Date”%>
<%@page contentType=”text/html” pageEncoding=”UTF-8″%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
<title>JSP Page</title>
<script>
function ss(){
alert(“11”);
}
</script>
</head>
<body>
<% out.print(“<script></script>”); %> //jsp调用js函数
<% String p=request.getParameter(“p”);%> //获取参数
<%=p%>//输出表达式
<% String s=request.getAttribute(“c”).toString();%>//获取设置的属性
<%=s%>
</body>
</html>

—————————-data.jsp——————————

<%@page contentType=”text/html” pageEncoding=”UTF-8″%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
<title>JSP Page</title>
</head>
<body>
<a href=”lijian.jsp?p=1″>lijian</a>
<%try{
int a=100;
int b=10;
request.setAttribute(“c”, a/b);//设置属性,跳转页面传值
}
catch(Exception e){
request.setAttribute(“c”, “error”); //设置属性,跳转页面传值
}
%>
<jsp:forward page=”lijian.jsp”></jsp:forward> 自动跳转界面
</body>
</html>