Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.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
Java 数据库网页中未显示用户名?_Java_Mysql_Database_Jsp_Servlets - Fatal编程技术网

Java 数据库网页中未显示用户名?

Java 数据库网页中未显示用户名?,java,mysql,database,jsp,servlets,Java,Mysql,Database,Jsp,Servlets,我已经用JSP制作了一个登录脚本。它的工作很好,但我使用的问题 它显示Null。你能告诉我这里怎么了吗 Main.jsp: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% if ((session.getAttribute("user_email") == null) || (session.getAttribute("u

我已经用JSP制作了一个登录脚本。它的工作很好,但我使用的问题
它显示
Null
。你能告诉我这里怎么了吗

Main.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

    <%
    if ((session.getAttribute("user_email") == null) || (session.getAttribute("user_email") == "")) {
        response.sendRedirect("login.jsp");
%>
<%} else
%>
<!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=UTF-8">
<title>Welcome to the job seeker forum.</title>
<link rel="stylesheet" type="text/css" href="CSS_styles/forum_style.css"/>
<link rel='stylesheet' id='open-sans-css'  href='//fonts.googleapis.com/css?family=Open+Sans%3A300italic%2C400italic%2C600italic%2C300%2C400%2C600&#038;subset=latin%2Clatin-ext&#038;ver=4.1-alpha-20141011' type='text/css' media='all' />
<link href='http://fonts.googleapis.com/css?family=Londrina+Solid|Exo:800|Open+Sans:300italic,400,300,600|Roboto:400,100,300,500,700' rel='stylesheet' type='text/css' />
</head>
<body>
    <div id="forum">
        <h1><b>Welcome <%=session.getAttribute("first_name")%></b>,<br>to Job seeker forum, there are many openings that you can get through here. <a href='logout.jsp'>logout</a></h1>
        <form id="forum_form" method="post">
        </form>
    </div><br><br><br>
    <div id="forum2">
        <h1 style="text-align: center;">Want to post on going walking,<br>Post your job description here.</h1>
        <form id="forum2_form" method="post">
            <p>
            <label>Job title:</label>
            <input type="text" class="" placeholder="e.g XXX Referral program for freshers."/>
            </p>
            <p>
            <label>Your Question:</label>
            <textarea class="question_ask_style" rows="3" cols="40" placeholder="Type description here.."></textarea>
            </p>

            <div id="submit_btn">
            <input type="submit" value="Submit Question" />
            </div>
        </form>
    </div>
</body>
</html>
这是我创建的
数据库表

create table `members`(
`id` int(10) unsigned NOT NULL auto_increment,
`email` varchar(100) NOT NULL,
`password` varchar(100) NOT NULL,
`first_name` varchar(50) NOT NULL,
`last_name` varchar(50) NOT NULL,
PRIMARY KEY(`id`)
)ENGINE= InnoDB default charset=latin1;
这就是我得到的错误

屏幕截图
显示
null
,因为您在会话中未设置
名字

您只设置了
用户\u电子邮件

if(rs.next()){
        String user_email=rs.getString("first_name");
        session.setAttribute("user_email", user_email);
        response.sendRedirect("main.jsp");
你可以像上面那样设置

附言


Scriptlet在过去几十年中一直不受欢迎,因此建议使用EL代替它们。您可以简单地使用,
${sessionScope.user\u email}
login\u process.jsp的jsp页面中打印出来,然后使用
访问它。 例如:

试试这个

if(rs.next()){
    session.setAttribute("user_email", user_email);

    session.setAttribute("first_name", rs.getString(4));//Add this line to your code


    response.sendRedirect("main.jsp");
}

这里4是login_process.jsp集合中first_name的列号

session.setAttribute("user_email", user_email);


因为您已经设置了属性名user\u email并从会话中获取第一个名称。

您没有设置
第一个名称
会话属性,所以显然无法获取它。第一个名称的session.setAttribute()在哪里?那么,如何获取会话属性,我就卡住了。。如何编写它,因为它从不从数据库调用..您可以从ResultSet rs中获取名字,因为您正在查询MenMembers表中的Select*,您可以从members表中获取名字详细信息。因此,如何获取会话属性
,我就卡住了。。如何编写它,因为它从不从数据库调用。您可以在login\u process.jsp上将其设置为
,但都德,它说
first\u name
是未知变量。。那么如何初始化它呢。。我真的被卡住了。。请帮助:(你在
会员表中有名字吗?
if(rs.next()){
    session.setAttribute("user_email", user_email);

    session.setAttribute("first_name", rs.getString(4));//Add this line to your code


    response.sendRedirect("main.jsp");
}
session.setAttribute("user_email", user_email);
    session.setAttribute("first_name", rs.getString("first_name"));