将JSP变量传递给Java函数?

时间:2015-09-08 13:53:05

标签: java jsp

我正在使用JSP文件,尝试在简单的登录页面上工作。

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="com.bridge.service.*" %>
<!-- needs to be run on server to resolve both errors -->
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!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">
    <link type="text/css" href="css/ui-lightness/jquery-ui-1.8.18.custom.css" rel="stylesheet" />
    <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.8.18.custom.min.js"></script>
    <title>Login </title>
</head>
<body>
    <form method="POST" name="frmLogon">
        User Email: <input type="text" name="email" value="<c:out value="${email}" />" /> <br /> 
        Password: <input type="text" name="password" value="<c:out value="${password}" />" /> <br />
        <jsp:useBean id="link" scope="application" class="com.bridge.service.Service" />
        <% 
            Service s = new Service();
            String token = s.logonToken(email, password);
        %>
        <input type="submit" value="Submit" />
    </form>
</body>
</html>

我很难理解如何从POST表单中获取这两个值并将它们传递给Java函数。这可能吗?我做错了吗?

1 个答案:

答案 0 :(得分:1)

对于简单的servlet,你应该使用:

String email = (String)request.getParameter("email");
String password = (String)request.getParameter("password");