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:
String myVariable = request.getParameter("myVariable");
Check the javadocs:
http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.