gpt4 book ai didi

java - jsp如何知道点击了哪个按钮

转载 作者:行者123 更新时间:2023-11-30 09:14:13 27 4
gpt4 key购买 nike

<分区>

带有两个按钮的Jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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">
<title>Insert title here</title>
</head>
<body>
<body style="background-color:black;">


<p>
<p><input type="button" name="good" value="Pen" onclick="location.href='hello';"> </p>
<p><input type="button" name="good" value="Paper" onclick="location.href='hello';">
</p>

</body>
</html>

这是servlet

package pack.exp;
import java.io.IOException;
import javax.servlet.http.*;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;


@SuppressWarnings("serial")
public class HelloServlet extends HttpServlet
{

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws
IOException
{
String val=req.getParameter("good");
if("Pen".equals(val))
{
resp.setContentType("text/plain");
resp.getWriter().println("Pen was clicked" );
}
else if("Paper".equals(val))
{
resp.setContentType("text/plain");
resp.getWriter().println("Paper was clicked");
}

}
}

我的代码在点击按钮时没有给出正确的输出。我希望当我单击 Pen 时它应该输入 if() 并打印文本,我希望纸张按钮也一样。

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