【发布时间】:2021-10-05 09:50:52
【问题描述】:
我想使用单个 jsp 文件来注册客户、供应商和托运人,但是当我使用
我能做些什么来解决这个问题?
下面我展示了 Supplier.jsp 和 Sign_in.jsp 的代码。对于客户和托运人的注册,jsp的实现方式与Supplier.jsp相同,只修改字符串“customer”和“shipper”的类型变量的值。这些页面将为每个 Customer、Shipper 和 Supplier 类显示更具体的值。
Supplier.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Bienvenido!</title>
</head>
<body>
<h2>Sign in</h2>
<a href="Sign_in.jsp">No account yet? Sign in</a>
<% request.getSession().setAttribute("type", "supplier"); %>
</body>
</html>
Register.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Sign in</title>
</head>
<body>
<h1>Sign in</h1>
<% String type = (String) request.getSession().getAttribute("type");
String supplier = "supplier";
String shipper = "shipper";
String client = "client";
%>
<% System.out.println(type.equals(supplier)); %>
<c:if test="${type == supplier}">
<h2>I'm a supplier</h2>
<form action="RegisterServlet" method="post">
<input type="email" name="email" placeholder="Email">
<input type="password" name="password" placeholder="Password">
<button type="submit">Register</button>
</form>
</c:if>
<c:if test="${type == shipper}">
<h2>I'm a shipper</h2>
<form action="RegisterServlet" method="post">
<input type="email" name="email" placeholder="Email">
<input type="text" name="user" placeholder="User">
<input type="password" name="password" placeholder="Password">
<button type="submit">Register</button>
</form>
</c:if>
<c:if test="${type == client}">
<h2>I'm a client</h2>
<form action="RegisterServlet" method="post">
<input type="email" name="email" placeholder="Email">
<input type="text" name="user" placeholder="User">
<input type="password" name="password" placeholder="Password">
<input type="text" name="city" placeholder="City">
<input type="text" name="address" placeholder="Address">
<input type="text" name="country" placeholder="Country">
<button type="submit">Register</button>
</form>
</c:if>
</body>
</html>
【问题讨论】: