EGL Development User Group

  • 1.  How to process a post request on the client side

    Posted Fri March 25, 2022 12:28 PM

    I'm trying to figure out how to process a post request on the client (RichUI) side.
    So far I tried to get the post request in the index.jsp file.
    Then read the post parameters with java and then set localStorage parameters or cookies with javascript.

    May be the index.jsp is the wrong file? 

    Regards,

    Marcel

    <%@ page import="java.util.Locale"%>
    <%@ page pageEncoding="UTF-8"%>
    <%
    	Locale locale = request.getLocale();
    	Enumeration enumeration = request.getParameterNames();
        String params = "";
    
        while(enumeration.hasMoreElements()){
            String parameterName = enumeration.nextElement();
            params += parameterName + "=" + request.getParameter(parameterName) + "&";
        }
    %>
    <script>
    	//window.localStorage.setItem('postParams', '<%=params%>');
    
             document.cookie='postParams=<%=params%>';
    </script>
    <html>
    	<% if ("fr".contains(locale.getLanguage())) { %>
    		<jsp:forward page="Start-fr_FR.html">
    		</jsp:forward>
    	<% } else { %>
    		<jsp:forward page="Start-nl_NL.html">
    		</jsp:forward>
    	<% } %>
    </html>​


    ------------------------------
    Marcel Beekman
    ------------------------------


  • 2.  RE: How to process a post request on the client side

    Posted Mon March 28, 2022 03:46 AM

    Hi,

    Sorry for the double posts.

    I didn't got a confirmation.

    Regards,

    Marcel



    ------------------------------
    Marcel Beekman
    ------------------------------



  • 3.  RE: How to process a post request on the client side

    Posted Tue March 29, 2022 02:15 AM
    Hi,
    I think it's only possible to get the "GET" parameters with external javascript.

    "getParameterFromUrl" : function(Parameter) {
    	var url_string = window.location.href;
    	var url = new URL(url_string);
    	Parameter = url.searchParams.get(Parameter);
    	return Parameter;
    }​

    The input "Parameter" of the function "getParameterFromUrl" is the parameter name and the return value ist the parameter value.

    If you don't want the user can see the parameter you can remove them after parsing.

    "delParameterFromUrl" : function() {
    	// get full URL
    	var currURL = window.location.href; // get current
    	// address
    	// Get the URL between what's after '/' and befor '?'
    	// 1- get URL after'/'
    	var afterDomain = currURL.substring(currURL
    			.indexOf('/') + 1);
    	// 2- get the part before '?'
    	var beforeQueryString = afterDomain.split("?")[0];
    
    	window.history.replaceState({}, document.title, "/"
    			+ beforeQueryString);
    }


    Kind Regards!



    ------------------------------
    Marcel Dreyer
    ------------------------------



  • 4.  RE: How to process a post request on the client side

    Posted Tue March 29, 2022 05:57 AM

    Hello Marcel,

    Thanks for your answer!

    I will try it if it works in my situation.

    Kind regards,

    Marcel



    ------------------------------
    Marcel Beekman
    ------------------------------



  • 5.  RE: How to process a post request on the client side

    Posted Mon April 04, 2022 10:25 AM

    Hello Marcel,

    Your code works, Thanks!

    Kind regards,

    Marcel



    ------------------------------
    Marcel Beekman
    ------------------------------