Пока я пытаюсь передать данные в jsp из сервлета, данные успешно передаются, но, похоже, это предупреждение, на самом деле я хочу отобразить его на новой странице jsp.Передача сервлета данных в jsp
вот мой сервлет и файл JSP, который я хочу, чтобы отобразить его,
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("Servlet called!!");
String feature=request.getParameter("id");
PrintWriter out = null;
Connection conn = null;
Statement stmt=null;
ResultSet rs;
try{
conn = JBDC.ConnectionFactory.getConnection();
// Execute SQL query
stmt = conn.createStatement();
String sql;
sql = "SELECT * FROM customers.add_voice where Feature='" +feature+ "'";
rs = stmt.executeQuery(sql);
// Extract data from DB
if(!rs.next()){
//Do nothing
}else{
do{
String price = rs.getString("Price");
response.setContentType("text/html");
request.setAttribute("feature", feature);
request.setAttribute("price", price);
request.getRequestDispatcher("/SelectedFeature.jsp").forward(request, response);
}while(rs.next());
}
// Clean-up
rs.close();
stmt.close();
conn.close();
}catch(SQLException se){
//Handle errors for JDBC
se.printStackTrace();
}catch(Exception e){
//Handle errors for Class.forName
e.printStackTrace();
}finally{
try{
if(stmt!=null)
stmt.close();
}catch(SQLException se2){
}
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}
}
}
// в JSP Я извлечение его
<%=(String)request.getAttribute("feature")%>
<%=(String)request.getAttribute("price")%>
// мой Jsp файл
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<META http-equiv="Content-Style-Type" content="text/css">
<script src="javascript/jquery-3.1.0.min.js"></script>
<script src="WebContent/javascript/basic.js"></script>
<script src="javascript/basic.js"></script>
<title>Insert title here</title>
</head>
<body>
<%=(String)request.getAttribute("feature")%>
<%=(String)request.getAttribute("price")%>
</body>
</html>
Что вы подразумеваете под этим, это похоже на предупреждение. Вы переходите на страницу, используя метод forward, и используя getAttribute() метод получения параметров. Что вам нужно в точности? – Santhucool
@Santhucool Я добавляю изображение pls, проверив его – cano
еще не видел фото – Santhucool