I am trying to attach a parameter to a URL on a servlet:
<a href="another_servlet?myVariable=<%=thevariable>> Go to this </a>
to be retrieved as a variable on another servlet that is called.
which contains the following code :
// 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();
It seems that I can use this code to fetch what I need
request.getAttribute
but I have searched almost everywhere and I cannot figure out how to put it all together. Thanks in advance.
No, those are query parameters. Use this to get that value:
Check the javadocs:
http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html