如何在java中使查询结果显示为超链接?

aamkag61  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(336)

下面显示的代码显示了数据库查询结果,但我希望将数据库中存储的每个j_标题作为超链接,以便人们可以单击它们并指向另一个jsp以显示自己的信息
这是我的密码
主页.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@ page import = "java.io.*,java.util.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
String id = request.getParameter("userid");
String driver = "com.mysql.jdbc.Driver";
String connectionUrl = "jdbc:mysql://localhost:3306/";
String database = "kps";
String userid = "root";
String password = "KPSAdmin1234!";
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
%>
<!DOCTYPE html>
<html>
<head>

</head>
<%
     Integer hitsCount = (Integer)application.getAttribute("hitCounter");
     if( hitsCount ==null || hitsCount == 0 ) {
        hitsCount = 1;
     } else {
        hitsCount += 1;
     }
     application.setAttribute("hitCounter", hitsCount);
  %>

<body>

<!-- container section start -->
<section class="centerDiv" class="" >

  <header class="header dark-bg">

        <!--logo start-->
        <a href="homepage.jsp" class="logo">Kumpulan Perangsang Selangor Berhad</span></a>
        <!--logo end-->
        <div class="top-nav notification-row">   
             <ul class="nav pull-right top-menu">
                 <a class="btn btn-info" href="login.jsp" title="Login"><span class="icon_house_alt"></span> Login</a>
            </ul>
        </div>
                &nbsp;
                <center><font size = "1"<p>Total number of visits: <%= hitsCount%></p></center>
  </header>      
  <!--header end-->

  <!--main content start-->

  <section class="centerDiv" class="col-lg-12 ">
      <section class="wrapper center " >
        <div class="centerDiv">
            <div class="centerDiv" >
                <section class="panel " > 

                  <font size = "2.5"><header class="panel-heading" style = "color:white; background-color: #FF6347;">&nbsp; Job Results</header>
               <div class="panel-body" class="tab-content" >
                    <div class="tab-content">
                        <div class="act-time">
                                 <span class="arrow"></span>
                                 <div class="text">
                                     <%
                                        try{
                                        connection = DriverManager.getConnection(connectionUrl+database, userid, password);
                                        statement=connection.createStatement();
                                        String sql ="select * from job";
                                        resultSet = statement.executeQuery(sql);
                                        while(resultSet.next()){
                                        %>
                                        <div class="act-time">                                      
                                           <div class="activity-body act-in">
                                                <span class="arrow" ></span>
                                                <div class="text" >
                                                    <a href="#" class="activity-img"></a>
                                                    <tr>
                                                    <font size="3"><td><strong><%=resultSet.getString("j_title") %></strong></td><br>
                                                    <font size="2"><td><%=resultSet.getString("j_location") %></td>
                                                    <font size="2">&ensp;|&ensp;<td><%=resultSet.getString("j_type") %></td>
                                                    <font size="2">&ensp;|&ensp;<td><%=resultSet.getString("j_empType") %></td>
                                                    </tr>
                                                </div>
                                           </div>
                                        </div>
                                        <%
                                        }
                                        connection.close();
                                        } catch (Exception e) {
                                        e.printStackTrace();
                                        }
                                        %>
                                 </div>                 
                        </div>
                    </div>  
                   <hr class="hr--logo">
                   <center><img src='img/logoperangsang.jpg' alt='logo' style="width:40px;height:40px;"></center><br>
                   <center><div class="footer-copyright">&copy; 2018 Kumpulan Perangsang Selangor Berhad.</div></center>
              </div>
            </div>
      </section>            
    </section>   
</section>
<!--main content end-->

</body>
</html>

这里的大多数答案是php,没有找到任何java的答案,所以请帮助我

nkkqxpd9

nkkqxpd91#

只需使用html

<a href='<%=resultSet.getString("j_title") %>'><%=resultSet.getString("j_title") %></a>

另请参阅这个链接,它展示了如何避免在jsp中使用java代码

相关问题