更改按钮点击时的jsp
我有一个问题。
我有3个jsp页面。 第一个是带有 2 个按钮的菜单。 当我单击第一个按钮时,我想打开第二个 jsp 页面。 当我单击第二个按钮时,我想打开第三个 jsp 页面。
你能帮助我吗?我必须使用 servlet(这不是问题,我知道)?
<%@ 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>
<form name="TrainerMenu" action="TrainerMenu" method="get">
<h1>Benvenuto in LESSON! Scegli l'operazione da effettuare:</h1>
<input type="button" value="Creazione Nuovo Corso" name="CreateCourse" />
<input type="button" value="Gestione Autorizzazioni"
name="AuthorizationManager" />
</form>
</body>
</html>
I have a question.
I have 3 jsp page.
The first is a menu with 2 button.
When I click the first button I want to open the second jsp page.
When I click the second button I want to open the third jsp page.
Can you help me? I must use a servlet(it's not a problem, i know it)?
<%@ 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>
<form name="TrainerMenu" action="TrainerMenu" method="get">
<h1>Benvenuto in LESSON! Scegli l'operazione da effettuare:</h1>
<input type="button" value="Creazione Nuovo Corso" name="CreateCourse" />
<input type="button" value="Gestione Autorizzazioni"
name="AuthorizationManager" />
</form>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您有多种选择,我将从最简单的开始:
1- 将输入按钮更改为链接,您可以使用 css 对其进行样式设置,使它们看起来像按钮:
而不是
2- 使用 javascript 更改表单的操作,具体取决于单击按钮:
3- 使用 servlet 或 JSP 处理请求并重定向或转发到适当的 JSP 页面。
You have several options, I'll start from the easiest:
1- Change the input buttons to links, you can style them with css so they look like buttons:
instead of
2- Use javascript to change the action of the form depending on the button you click:
3- Use a servlet or JSP to handle the request and redirect or forward to the appropriate JSP page.
您可以制作这些提交按钮,并在您提交表单的 servlet 内,您可以测试按下的按钮的名称并呈现相应的 jsp 页面。
在
TrainerMenu
servlet 中,如果request.getParameter("CreateCourse")
不为空,则单击第一个按钮,您可以渲染相应的 jsp。You could make those submit buttons and inside the servlet your are submitting the form to you could test the name of the button which was pressed and render the corresponding jsp page.
Inside the
TrainerMenu
servlet ifrequest.getParameter("CreateCourse")
is not empty then the first button was clicked and you could render the corresponding jsp.最简单的方法是使用 java 脚本。
例如,
The simplest way you can do this is to use java script.
For example,
<input type="button" value="load" onclick="window.location='userpage.jsp'" >
如果您要查找的只是从第一页导航到第二页和第三页,请将按钮替换为锚元素,如下所示:
如果由于某种原因您需要使用按钮,请尝试以下操作:
If all you are looking for is navigation to page 2 and 3 from page one, replace the buttons with anchor elements as below:
If for some reason you need to use buttons, try this:
只需使用两种形式即可。
在第一个表单中,操作属性将包含第二个 jdp 页面的名称和第一个按钮。在第二种形式中,将有第二个带有操作属性的按钮,该属性给出了第三个 jsp 页面的名称。
它将是这样的:
Just use two forms.
In the first form action attribute will have name of the second jdp page and your 1st button. In the second form there will be 2nd button with action attribute thats giving the name of your 3rd jsp page.
It will be like this :
如果您想单击按钮而不是其他方式。您可以通过将
location.href
添加到按钮来完成此操作。这是我使用的方法上面的按钮使用引导类进行样式设置。如果没有样式,最简单的代码将是
/dashboard
是我的 JSP 页面,如果您也使用扩展,则使用/dashboard.jsp
If you wanna do with a button click and not the other way. You can do it by adding
location.href
to your button. Here is how I'm usingThe button above uses bootstrap classes for styling. Without styling, the simplest code would be
The
/dashboard
is my JSP page, If you are using extension too then used/dashboard.jsp
它使用ajax 工作。
然后,该 jsp 将显示在控制器响应请求而返回的 iframe 中。
It works using ajax.
The jsp then display in iframe returned by controller in response to request.
你输入--action =“提交”
按钮内部
you put -- action = "submit"
inside of the button