更改按钮点击时的jsp

发布于 2024-10-10 02:23:00 字数 962 浏览 0 评论 0原文

我有一个问题。

我有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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

峩卟喜欢 2024-10-17 02:23:00

您有多种选择,我将从最简单的开始:

1- 将输入按钮更改为链接,您可以使用 css 对其进行样式设置,使它们看起来像按钮:

<a href="CreateCourse.jsp">Creazione Nuovo Corso</a>

而不是

<input type="button" value="Creazione Nuovo Corso" name="CreateCourse" />

2- 使用 javascript 更改表单的操作,具体取决于单击按钮:

<input type="button" value="Creazione Nuovo Corso" name="CreateCourse" 
onclick="document.forms[0].action = 'CreateCourse.jsp'; return true;" />

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:

<a href="CreateCourse.jsp">Creazione Nuovo Corso</a>

instead of

<input type="button" value="Creazione Nuovo Corso" name="CreateCourse" />

2- Use javascript to change the action of the form depending on the button you click:

<input type="button" value="Creazione Nuovo Corso" name="CreateCourse" 
onclick="document.forms[0].action = 'CreateCourse.jsp'; return true;" />

3- Use a servlet or JSP to handle the request and redirect or forward to the appropriate JSP page.

放肆 2024-10-17 02:23:00

您可以制作这些提交按钮,并在您提交表单的 servlet 内,您可以测试按下的按钮的名称并呈现相应的 jsp 页面。

<input type="submit" value="Creazione Nuovo Corso" name="CreateCourse" />
<input type="submit" value="Gestione Autorizzazioni" name="AuthorizationManager" />

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.

<input type="submit" value="Creazione Nuovo Corso" name="CreateCourse" />
<input type="submit" value="Gestione Autorizzazioni" name="AuthorizationManager" />

Inside the TrainerMenu servlet if request.getParameter("CreateCourse") is not empty then the first button was clicked and you could render the corresponding jsp.

抽个烟儿 2024-10-17 02:23:00

最简单的方法是使用 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'" >

独守阴晴ぅ圆缺 2024-10-17 02:23:00

如果您要查找的只是从第一页导航到第二页和第三页,请将按钮替换为锚元素,如下所示:

<form name="TrainerMenu" action="TrainerMenu" method="get">

<h1>Benvenuto in LESSON! Scegli l'operazione da effettuare:</h1>
<a href="Page2.jsp" id="CreateCourse" >Creazione Nuovo Corso</a> 
<a href="Page3.jsp" id="AuthorizationManager">Gestione Autorizzazioni</a>
<input type="button" value="" name="AuthorizationManager" />
</form>

如果由于某种原因您需要使用按钮,请尝试以下操作:

<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"
    onclick="openPage('Page2.jsp')"/>
   <input type="button" value="Gestione Autorizzazioni" name="AuthorizationManager"
    onclick="openPage('Page3.jsp')" />

</form>
<script type="text/javascript">
 function openPage(pageURL)
 {
 window.location.href = pageURL;
 }
</script>

If all you are looking for is navigation to page 2 and 3 from page one, replace the buttons with anchor elements as below:

<form name="TrainerMenu" action="TrainerMenu" method="get">

<h1>Benvenuto in LESSON! Scegli l'operazione da effettuare:</h1>
<a href="Page2.jsp" id="CreateCourse" >Creazione Nuovo Corso</a> 
<a href="Page3.jsp" id="AuthorizationManager">Gestione Autorizzazioni</a>
<input type="button" value="" name="AuthorizationManager" />
</form>

If for some reason you need to use buttons, try this:

<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"
    onclick="openPage('Page2.jsp')"/>
   <input type="button" value="Gestione Autorizzazioni" name="AuthorizationManager"
    onclick="openPage('Page3.jsp')" />

</form>
<script type="text/javascript">
 function openPage(pageURL)
 {
 window.location.href = pageURL;
 }
</script>
眉黛浅 2024-10-17 02:23:00

只需使用两种形式即可。

在第一个表单中,操作属性将包含第二个 jdp 页面的名称和第一个按钮。在第二种形式中,将有第二个带有操作属性的按钮,该属性给出了第三个 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>
    <form name="main1"  method="get" action="2nd.jsp">
        <input type="submit" name="ter" value="LOGOUT" >
    </form>
    <DIV ALIGN="left"><form name="main0" action="3rd.jsp" method="get">
        <input type="submit" value="FEEDBACK">
    </form></DIV>
</body>
</html>

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 :

<%@ 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="main1"  method="get" action="2nd.jsp">
        <input type="submit" name="ter" value="LOGOUT" >
    </form>
    <DIV ALIGN="left"><form name="main0" action="3rd.jsp" method="get">
        <input type="submit" value="FEEDBACK">
    </form></DIV>
</body>
</html>
转身以后 2024-10-17 02:23:00

如果您想单击按钮而不是其他方式。您可以通过将 location.href 添加到按钮来完成此操作。这是我使用的方法

<button class="btn btn-lg btn-primary" id="submit" onclick="location.href ='/dashboard'" >Go To Dashboard</button>

上面的按钮使用引导类进行样式设置。如果没有样式,最简单的代码将是

<button onclick="location.href ='/dashboard'" >Go To Dashboard</button>

/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 using

<button class="btn btn-lg btn-primary" id="submit" onclick="location.href ='/dashboard'" >Go To Dashboard</button>

The button above uses bootstrap classes for styling. Without styling, the simplest code would be

<button onclick="location.href ='/dashboard'" >Go To Dashboard</button>

The /dashboard is my JSP page, If you are using extension too then used /dashboard.jsp

黑色毁心梦 2024-10-17 02:23:00

它使用ajax 工作。
然后,该 jsp 将显示在控制器响应请求而返回的 iframe 中。

function openPage() {
  jQuery.ajax({
  type : 'POST',
  data : jQuery(this).serialize(),
  url : '<%=request.getContextPath()%>/post_action',
  success : function(data, textStatus) {
  jQuery('#iframeId').contents().find('body').append(data);
  },
  error : function(XMLHttpRequest, textStatus, errorThrown) {
  }
  });
}

It works using ajax.
The jsp then display in iframe returned by controller in response to request.

function openPage() {
  jQuery.ajax({
  type : 'POST',
  data : jQuery(this).serialize(),
  url : '<%=request.getContextPath()%>/post_action',
  success : function(data, textStatus) {
  jQuery('#iframeId').contents().find('body').append(data);
  },
  error : function(XMLHttpRequest, textStatus, errorThrown) {
  }
  });
}
凤舞天涯 2024-10-17 02:23:00

你输入--action =“提交”
按钮内部

you put -- action = "submit"
inside of the button

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文