在jsp中从php读取参数

时间:2014-03-09 10:43:26

标签: php html jsp

我在php中有以下代码片段

if($userName==$dbUserName&&md5($passWord)==$dbPassWord){

            echo "<input name='username' type='hidden' value='$userName'>";
            header('Location: http://localhost:8080/ClientModule/student.jsp');
            die();

        }

php重定向到以下jsp

<%@page contentType="text/html" pageEncoding="UTF-8" errorPage="error.jsp"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Student Home</title>
    </head>
    <body>
        <h1>
            Logged in as: ${param.username}
        </h1>
        <nav>
            <p><a href="student.jsp">Home</a></p>
            <p><a href="profile.jsp">Profile</a></p>
            <p><a href="tutorList.jsp">Teachers</a></p> 
            <p><a href="studentNotifs.jsp">Notifications</a></p> 
        </nav>
    </body>
</html>

我一定在php文件中做错了,有人能帮我发现它吗? 非常感谢任何帮助

1 个答案:

答案 0 :(得分:0)

执行此操作时:

        header('Location: http://localhost:8080/ClientModule/student.jsp');

浏览器只是对指定的URL执行GET请求。您在上面的行中回显的表单字段不包含在此请求中。相反,你想要的是这样的:

        header('Location: http://localhost:8080/ClientModule/student.jsp?username='.$userName);