Web app with input parameter as a url argument

23 visualizaciones (últimos 30 días)
Rachid Rezgui
Rachid Rezgui el 25 de Ag. de 2023
Comentada: Ingo Hermann el 26 de Abr. de 2024
How can I pass an argument from the url of the app to the app? Say for example the app is a dropdown with 3 items. The url is www.matlabapp.com/app1. if I type www.matlabapp.com/app1?dropdownItem=2 in the browser, it should automatically preselect the 2nd item from the drop down.

Respuestas (1)

Raj
Raj el 11 de Sept. de 2023
Faisal ha marcado con alerta este/a respuesta
Hi,
I understand you are trying to pass an argument from the URL of the app to the app itself.
I’ll suggest few basic steps that will help you in the same-
  • The first step is defining the URL structure. In your example, the URL `www.matlabapp.com/app1?dropdownItem=2` includes the `dropdownItem` parameter with a value of `2`.
  • In the next step you’ll have to retrieve that argument in your app. In MATLAB, you can use the `webread` function to retrieve the URL and extract the parameter value:
url = 'http://www.matlabapp.com/app1?dropdownItem=2';
dropdownItem = webread(url, 'dropdownItem');
  • Once you have the value of the `dropdownItem` parameter, you can use it to preselect the corresponding item in your dropdown. In MATLAB, assuming you have a dropdown object named `myDropdown`, you can set the selected item based on the `dropdownItem` value:
myDropdown.Value = dropdownItem;
I have assumed that your dropdown items are zero-based indexed. If your dropdown items are one-based indexed, you will need to adjust the value accordingly.
Additionally refer to the documentation of ‘webread’ from MathWorks for better understanding
I hope this resolves your query!
  1 comentario
Ingo Hermann
Ingo Hermann el 26 de Abr. de 2024
And how can I get the url from the actual running WebApp?
I need a command to read the url how the WebApp ist opened.

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB Web App Server en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by