首页 > 解决方案 > 更改按钮单击jsp上的背景颜色

问题描述

我最近开始学习网络编程,我想实现一个改变背景颜色的应用程序。我的页面上有 4 个按钮。我做了点什么。但它不起作用。我知道,我可以使用 js。但这不会是正确的。请帮我。

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<form action = "apps" method="POST">
        <input  type="submit" name="red" value ="red" >



        <input  type="submit" name="blue" value ="blue" >
        <input  type="submit" name="green" value ="green" >
        <input  type="submit" name="yellow" value ="yellow" >
        <input  type="submit" name="reset" value ="reset" >
        </form>
<%
String button1Click = request.getParameter("red");
if(button1Click.equals("red")){
    <body style='background-color:#red;'>;
}

%>
</form>
</body>
</html>

标签: jspbutton

解决方案


您应该在输入 html 之前关闭 java scriptlet 标记,并在输入 html 后再次打开它。

%>
<body style='background-color: red;'>
<%

并且您可能希望从表单中删除该action属性,<form>因为表单应该传递给相同的 url。


推荐阅读