Set String to clickable URL

2019-03-06 10:51发布

问题:

Am I able to change one the attribute from normal text become an URL(hyperlink) so user will be able to click on it and redirect to another page.

Basically the attribute that I get from servlet is www.stackoverflow.com but is in plain text so my question is how do I change it to a clickable link?

Any expert out there know how to set it? Thank you so much and have a nice day!

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.util.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="2nd.css">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>THE SUPER SEARCH</title>
    </head>
    <body>
        <h4>Here's the following results</h4>
        <%
            String testresults=(String)request.getAttribute("testresults");
            out.print("" + testresults);
        %>
        <br>
        <br>
        <% 
            String testcontent=(String)request.getAttribute("testcontent");
            out.print("" + testcontent);
        %>
    </body>
</html>

回答1:

Put it inside an <a> tag.
Something like

<a href="<%=testresults%>"><%=testresults%></a>

Regards