I just starting learning about servlets yersterday so I’m a newbie. I read a tutorial and made the following program to track the use of a link:
package red;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/Redirection")
public class Redirection extends HttpServlet {
private static final long serialVersionUID = 1L;
private String referrer;
private String target;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
getURLs(request);
}
catch(Exception e)
{
response.sendError(500, "Target parameter not specified");
return;
}
response.sendRedirect(target);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
public void getURLs(HttpServletRequest request)
{
referrer = request.getParameter("referrer");
if(referrer == null || 0 == referrer.length())
{
referrer = new String("");
}
target = request.getParameter("target");
if(target == null || target.equals(""))
{
throw new IllegalArgumentException();
}
}
}
But when I teste it(Eclipse with Tomcat) i get this:
HTTP Status 500 - Target parameter not specified
How do I specify a target parameter in eclipse so I can run this program ?
Sorry for the beginner question.
Well you don’t really know what’s going on here. Maybe you’re getting a different exception – you’re giving that error message whatever goes wrong. You should log exactly what’s being thrown. You also shouldn’t generally catch
Exceptionyourself – catch more specific exceptions.Anyway, normally to include that sort of parameter, you’d just put it in the URL: