我正在尝试在会话范围内设置值,但未设置请发现问题异常即将到来:
<%String name=request.getParameter("name");%><% if(request.getParameter("name").equals(name)){session.setAttribute("EmployeeById",name);}%>
在这里您可以找到实际上我想在会话中设置按钮值的代码,并且我正在使用其他 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">
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jstl/xml" %>
<html>
<head>
<script type="text/javascript">
function popuponclick() {
var mywindow = window.open("file.jsp", "file", "status=1,width=350,height=150");
}
</script>
</head>
<body>
<form name="form1">
<%String name = request.getParameter("name");%>
<% if (request.getParameter("name").equals(name)) {
session.setAttribute("EmployeeById", name);
}
%>
<table>
<tr>
<td><input type="submit" onclick="popuponclick()" value="GetEmployeeById" name="name"/>
<input type="hidden" name="GetEmp" value="1"></td>
</tr>
<tr>
<td><input type="submit" onclick="popuponclick()" value="GetEmployeeByname" name="name1"></td>
</tr>
</table>
</form>
</body>
</html>
我的第二个 .jsp 就是我通过会话范围获取值的地方
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%>
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql"%>
<%@ taglib prefix="x" uri="http://java.sun.com/jstl/xml"%>
<%@page
import="com.nousinfo.tutorial.employee.service.model.bo.EmployeeBO"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<%
String attributeValue = (String)session.getAttribute("EmployeeById");
out.println(attributeValue);
%>
<body>
<% if ("GetEmployeeById".equals(attributeValue)) { %>
<div>
<table>
<tr>
<td>GetEmployeeByName</td>
</tr>
<tr>
<td><input type="text" name="GetEmployeeByName"/></td></tr>
</table>
</div>
<% } else { %>
<div>
<table>
<tr>
<td>GetEmployeeById</td>
</tr>
<tr>
<td><input type="text" name="GetEmployeeById"/></td></tr>
</table>
</div>
<% } %>
<table>
<tr>
<td><input type="submit" name="submit" value="find"></td>
</tr>
</table>
</body>
</html>