簡體   English   中英

使用Java Servlet(Jetty)從URL檢索數據

[英]Retrieving data from a URL using a Java Servlet (Jetty)

我正在嘗試將參數附加到servlet上的URL:

<a href="another_servlet?myVariable=<%=thevariable>> Go to this </a>

被作為另一個servlet上的變量檢索。

其中包含以下代碼:

// Database access with a servlet
package ubiserv.simple;

import java.io.*;
import java.util.*;
import javax.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Product extends HttpServlet {
public void service(HttpServletRequest request,HttpServletResponse response)
        throws IOException, ServletException{

        response.setContentType("text/html");
        PrintWriter out = response.getWriter();

看來我可以使用此代碼來獲取所需的信息

request.getAttribute

但是我幾乎在所有地方都進行了搜索,無法弄清楚如何將它們組合在一起。 提前致謝。

不,這些是查詢參數。 使用它來獲得該值:

String myVariable = request.getParameter("myVariable");

檢查javadocs:

http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM