[英]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.