Probleme sendRedirect dans ma servlet
Bonjour,
En fait, quand je clique sur le bouton de validation de ma page address.jsp, j'atteris bien dans ma servlet où l'instruction response.sendRedirect(getServletContext()+"/accessibilityResult.jsp"); me redirige bien vers la page accessibility.jsp mais dans la barre d'adresse, il est toujours indiqué "http://localhost:8080/geoAccessibility/MyServlet".
Où est le problème ?
Et sinon, y a-t-il quand-même moyen d'utiliser un forward sur un objet RequestDispatcher tout en ayant un changement dans la barre d'adresse ?
Voici le code :
MyServlet.java
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
package com.application.geoAccessibility;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MyServlet extends HttpServlet {
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
RequestDispatcher rd = request.getRequestDispatcher("/index.jsp");
rd.forward(request, response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
String streetName = request.getParameter("streetName");
String streetNumber = request.getParameter("streetNumber");
String zipCode = request.getParameter("zipCode");
String city = request.getParameter("city");
String country = request.getParameter("country");
response.sendRedirect(getServletContext()+"/accessibilityResult.jsp");
}
} |
address.jsp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
<%@ 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">
<link rel="stylesheet"
href="https://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
<script type="text/javascript"
src="https://code.jquery.com/jquery-2.0.2.min.js"></script>
<script type="text/javascript"
src="https://code.jquery.com/jquery-2.0.2.js"></script>
<script type="text/javascript"
src="https://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
<style type="text/css">
input::-webkit-input-placeholder { font-size:2em; }
input::-moz-placeholder { font-size:2em; } /* FF 19+ */
input:-moz-placeholder { font-size:2em; } /* FF 18- */
input:-ms-input-placeholder { font-size:2em; }
.placeholder { font-size:2em; } /* for the polyfill */
</style>
<script>
$(document).ready(function(){
$('#backButton').children().children().css("font-size","4em");
$('#backButton').children().children().css("text-align","center");
$('#validationBtn').children().children().css("font-size","3em");
var windowHeight = $(document).height()/16;
var headerHeight = $.mobile.activePage.children('[data-role="header"]').height() / 16;
var rest = (windowHeight - headerHeight) /3.5;
$('#streetName').parent().css("height",rest/4+"em");
$('#streetNumber').parent().css("height",rest/4+"em");
$('#city').parent().css("height",rest/4+"em");
$('#zipCode').parent().css("height",rest/4+"em");
$('#country').parent().css("height",rest/4+"em");
});
</script>
<title>GeoAccessibility - Type your address</title>
</head>
<body>
<div data-role="page" data-ajax="false" id="page1">
<div id="header" data-theme="b" data-role="header">
<a id="backButton" data-role="button" data-icon="arrow-l" data-ajax="false" style="width:12em;height:5em;margin-top:0.5em;" href="index.jsp">Back</a>
<h3 style="font-size:2.5em;">
GeoAccessibility
</h3>
</div>
<div data-role="content">
<form method ="post" action="MyServlet" data-ajax="false">
<input name="streetName" id="streetName" placeholder="Street" value="" type="text">
<input name="streetNumber" id="streetNumber" placeholder="N°" value="" type="text">
<input name="zipCode" id="zipCode" placeholder="Zip Code" value="" type="text">
<input name="city" id="city" style="width:75%;" placeHolder="City" value="" type="text">
<input name="country" id="country" placeHolder="Country" value="" type="text">
<button id="validationBtn" data-role="button" data-theme="b" data-ajax="false" type="submit" data-theme="b">Sign in</a>
</form>
</div>
</div>
</body>
</html> |
accessibilityResult.jsp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
<%@ 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">
<link rel="stylesheet"
href="https://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
<script type="text/javascript"
src="https://code.jquery.com/jquery-2.0.2.min.js"></script>
<script type="text/javascript"
src="https://code.jquery.com/jquery-2.0.2.js"></script>
<script type="text/javascript"
src="https://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
<title>GeoAccessibility - Results</title>
</head>
<body>
<div data-role="page" id="page1">
<div data-theme="b" data-role="header">
<a data-role="button" data-icon="arrow-l" style="width:8em;margin-top:0.5em;" href="index.jsp">Back</a>
<h3 style="font-size:1.5em;">
GeoAccessibility
</h3>
</div>
<div data-role="content">
<div style="text-align:center;font-size:3em;">Accessibility Index</div>
<div style="margin-left:20%;">
<label id="accessibilityIndex" style="display:block;width:50em;height:20em;background-color:black;color:white;text-align:center;">
<div style="font-size:4em;padding-top:2em;">00%</div>
</label>
</div>
<a data-role="button" data-theme="b">Resultats graphiques</a>
<a data-role="button" data-theme="b">Resultats complets</a>
</div>
</div>
</body>
</html> |