Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change jsp on button click

Tags:

java

jsp

servlets

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>
like image 378
zp26 Avatar asked Jan 03 '11 09:01

zp26


People also ask

How can I redirect a button to another page in JSP?

The page redirect is used to move the redirect response to another resource of the web page. Basically we can call the redirect pages using sendRedirect() method in the jsp on client-side request can be used within the server or outside of the server.

How to use post method in JSP?

POST method This message comes to the backend program in the form of the standard input which you can parse and use for your processing. JSP handles this type of requests using getParameter() method to read simple parameters and getInputStream() method to read binary data stream coming from the client.

How can a JSP receives the user submitted form data?

JSP handles form data processing by using following methods: getParameter():It is used to get the value of the form parameter. getParameterValues():It is used to return the multiple values of the parameters. getParameterNames()It is used to get the names of parameters.


2 Answers

The simplest way you can do this is to use java script. For example, <input type="button" value="load" onclick="window.location='userpage.jsp'" >

like image 162
Nandhini Avatar answered Oct 14 '22 11:10

Nandhini


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.

like image 34
Abdullah Jibaly Avatar answered Oct 14 '22 12:10

Abdullah Jibaly