简体   繁体   English

将 JSP 变量传递给 Java 函数?

[英]Passing JSP variable to Java function?

I am working with a JSP file, trying to work on a simple logon page.我正在处理一个 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>

I am having a hard time understanding how to take the two values from the POST form and passing them to the Java function.我很难理解如何从 POST 表单中获取两个值并将它们传递给 Java 函数。 Is this possible?这可能吗? Am I doing this incorrectly?我这样做不正确吗?

For simple servlet, you shouod use:对于简单的 servlet,您应该使用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM