在jsp中从php读取参数

时间:2022-09-19 11:49:05

I have the following code snippet in php

我在php中有以下代码片段

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

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

        }

the php redirects to the following jsp

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>

I must have done something wrong in the php file, can someone help me spot it? Any help is much appreciated

我必须在php文件中做错了,有人能帮我发现吗?任何帮助深表感谢

1 个解决方案

#1


0  

When you do this:

当你这样做:

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

The browser simply does a GET request to the specified URL. The form field you echo out on the line above is not included in this request. In stead, what you want is something like this:

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

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

#1


0  

When you do this:

当你这样做:

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

The browser simply does a GET request to the specified URL. The form field you echo out on the line above is not included in this request. In stead, what you want is something like this:

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

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