gpt4 book ai didi

java - jsp包含不起作用

转载 作者:行者123 更新时间:2023-12-01 10:40:18 25 4
gpt4 key购买 nike

login.html
该文件包含 2 个按钮的代码。登录和注册按钮有 2 种形式。
connected.jsp
该文件包含 1 个按钮的代码,用户可以单击该按钮并退出。
Controller .jsp

<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="something.*" %>
<%@ page errorPage="Error.jsp" %>

<%

request.setCharacterEncoding("ISO-8859-7");
String errorMessages = "";
String username = request.getParameter("username");
String password = request.getParameter("password");
if ((password.length() > 0) && !(username.length() > 0)) {
errorMessages = ("message1");
throw new Exception(errorMessages);
}
if ((username.length() > 0) && !(password.length() > 0)) {
errorMessages = ("message2");
throw new Exception(errorMessages);
}
if (!(password.length() > 0) && !(username.length() > 0)) {
errorMessages = ("message3");
throw new Exception(errorMessages);
}
DB_something db = new DB_something ();
db.open();
if (request.getParameter("FistName") == null) {
db.authenticateUser(username, password);
session.setAttribute("login_status", "connected");

} else {
String fName = request.getParameter("FistName");
String lName = request.getParameter("LastName");
String email = request.getParameter("email");
String gender = request.getParameter("sex");
String month = request.getParameter("month");
String day = request.getParameter("day");
String year = request.getParameter("year");
String address = request.getParameter("Adress");
db.registerUser(fName, lName, email, username, password, gender, month, day, year, address);
session.setAttribute("login_status", "connected");
}
db.close();
%>
<jsp:forward page="index.jsp" />

DB_something 是一个类,用于打开和关闭与数据库的连接,检查登录是否正常,并在注册时注册用户

index.jsp

    <%
if (request.getParameter("login_status") == null) {
%>
<jsp:include page="login.html" />
<%
} else {
if(1==1)
throw new Exception("error...");
%>
<jsp:include page="connected.jsp" />
<%
}
%> . . . .

在我的index.jsp中,如果用户未连接(login_status = null),我尝试包含login.html,如果用户已连接,则包含connected.jsp(login_status =“connected”)问题是它不起作用。它总是添加 login.html..我什至尝试添加抛出异常(if 1==1 是因为否则抛出异常..)但输出始终相同(异常永远不会工作)有什么想法吗?

最佳答案

您将属性保存在 session 中,但尝试从请求中提取它。

代替指令 -

<jsp:forward page="index.jsp" />

使用这个:

<jsp:forward page="index.jsp">
<jsp:param name="login_status" value="connected" />
</jsp:forward>

或者从 session 中提取属性:

if(request.getSession().getAttribute("login_status") == null) {
...
}

关于java - jsp包含不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34456561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com