gpt4 book ai didi

jsp - servlet 中的 Ahref

转载 作者:行者123 更新时间:2023-11-28 23:44:45 25 4
gpt4 key购买 nike

我目前正在使用教程 ( http://www.java-programming.info/tutorial/pdf/csajsp2/07-Cookies.pdf ) 来尝试启用 cookie 创建,我的 servlet 在下面的代码中有特色,但是我想添加一个 href 或按钮,以便当用户受到欢迎时,他们可以单击并被带到我的 webContent 文件夹中的一个 jsp,我正在使用 jsp、eclipse indigo 和 tomcat 6,任何提示都会真正帮助添加 href,如下所示不起作用,顺便说一句,可以忽略代码中的 w3schools 链接

package The_Quiz;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

/** Servlet that processes a registration form containing
* a user's first name, last name, and email address.
* If all the values are present, the servlet displays the
* values. If any of the values are missing, the input
* form is redisplayed. Either way, the values are put
* into cookies so that the input form can use the
* previous values.
* <p>
* From <a href="http://courses.coreservlets.com/Course-Materials/">the
* coreservlets.com tutorials on servlets, JSP, Struts, JSF, Ajax, GWT, and Java</a>.
*/

public class RegistrationServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
boolean isMissingValue = false;
String firstName = request.getParameter("firstName");
if (isMissing(firstName)) {
firstName = "Missing first name";
isMissingValue = true;
}
String lastName = request.getParameter("lastName");
if (isMissing(lastName)) {
lastName = "Missing last name";
isMissingValue = true;
}
String emailAddress = request.getParameter("emailAddress");
if (isMissing(emailAddress)) {
emailAddress = "Missing email address";
isMissingValue = true;
}
Cookie c1 = new LongLivedCookie("firstName", firstName);
response.addCookie(c1);
String formAddress =
"The_Quiz.RegistrationForm";
if (isMissingValue) {
response.sendRedirect(formAddress);
} else {
PrintWriter out = response.getWriter();
String docType =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
"Transitional//EN\">\n";
String title = "Thanks for Registering";
out.println
(docType +
"<HTML>\n" +
"<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<CENTER>\n" +
"<H1 ALIGN>" + title + "</H1>\n" +
"<UL>\n" +
" <LI><B>First Name</B>: " +
firstName + "\n" +
"</UL>\n" +
"<a href="Question_1.jsp">Visit W3Schools</a>" +
"</CENTER></BODY></HTML>");
}
}

/** Determines if value is null or empty. */

private boolean isMissing(String param) {
return((param == null) ||
(param.trim().equals("")));
}
}

最佳答案

你添加了一个cookie,但是你得到了一个请求参数。你应该按照书中的例子创建CookieUtilities并使用CookieUtilities.getCookieValue如果你想获取参数 - 你需要在你的 URL 中发送请求参数

关于jsp - servlet 中的 Ahref,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15852280/

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