Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
574 views
in Technique[技术] by (71.8m points)

jstl - JSP:redirect url with dynamic value

I have the below code :

<c:redirect url= "someFile.jsp">

But I need to use the host name when I do the redirect. Somewhat like below :

String servername = request.getServerName();
String myAppUrl   = "https://" + servername + "/myApp/";

<c:redirect url= myAppUrl + "someFile.jsp">

But I am getting error with the above code. Tried the below methods as well but none are working :

<c:redirect url= ${myAppUrl} + "someFile.jsp">
<c:redirect url= "${myAppUrl}" + "someFile.jsp">

See my problem is not about fetching the request object.. I can do that and able to access the hostname, context path etc.. But I need to pass them to the url value which i am not sure how to do. Can someone tell me how can use the dynamic url in the above redirection.

question from:https://stackoverflow.com/questions/65937311/jspredirect-url-with-dynamic-value

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Below fix is working for me :

String servername = request.getServerName();
String myAppUrl   = "https://" + servername + "/myApp/";
String myJspUrl   = myAppUrl + "someFile.jsp";

request.setAttribute("myJspUrl", myJspUrl);
%>
<c:redirect url= "${myJspUrl}">
<%

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...