Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在jsp上“html”输入字段的值属性中使用会话对象_Jsp_Servlets - Fatal编程技术网

如何在jsp上“html”输入字段的值属性中使用会话对象

如何在jsp上“html”输入字段的值属性中使用会话对象,jsp,servlets,Jsp,Servlets,我使用rollno作为会话对象,我必须在“html”输入字段的value属性中使用该值,这里是我的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.o

我使用rollno作为会话对象,我必须在“html”输入字段的value属性中使用该值,这里是我的
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">
     <%@page import="javax.servlet.http.HttpSession"%> 
     <html>
     <head>
     <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
     <title>Insert title here</title>
     <%!HttpSession value=null; %>
     </head>
     <body>
     <form action="ShowMarkServlet">
     <% value=(HttpSession)session.getAttribute("rollno");%>
     <%out.print(session.getAttribute("rollno")); %>
     Rollnumber:<input type="number" value="<%=value%>" name="rollno"><br>
     Enter the semester:<input type="number" name="semester" min="0" max="6">
     <input type="submit" value="okay">
     </form>
     </body>
     </html>

您只需通过
会话
,就可以从jsp访问会话,因此您的代码应该如下所示:

<% String value=session.getAttribute("rollno");%>
<% out.print(value); %>

或使用:


在此处插入标题
卷号:
进入学期:

如果我没有弄错你的意图

这取决于你将如何处理它,要知道这些HTML是由servlet形成的,jsp在编译后在servlet中进行转换好的,但是如何访问会话对象,它在jsp显示中显示null
会话就在那里,保存着你在那里写的值,无论如何,您不应该比在jsp中使用
session
更难,而且在EL中,所有变量都是通过请求和会话查看的,所以您甚至不应该担心它们在哪里。我的意图是一样的,但它太不起作用了${rollno}
session.setAttribute(字符串arg,“obj”)
我们不能将一个对象保存在字符串中`我刚刚按照您的示例编写了字符串,任何对象都可以存储在会话中,然后您应该将其作为对象访问,例如:
request.getSession().setAttribute(“rollno”,a)
在servlet中,a是a的对象,那么在jsp中您应该执行
a=(a)getAttribute(“rollno”)
和,您可以将其用作对象,访问其字段和方法
<% String value=session.getAttribute("rollno");%>
<% out.print(value); %>
    <%@ 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 action="ShowMarkServlet">
 Rollnumber:<input type="number" value="${rollno}" name="rollno"><br>
 Enter the semester:<input type="number" name="semester" min="0" max="6">
 <input type="submit" value="okay">
 </form>
 </body>
 </html>