我目前正在尝试运行一个检查 GET 值并写入该值的 servlet。
这是我的课:
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Servlet extends HttpServlet {
/**
*
*/
public Servlet() {
// TODO Auto-generated constructor stub
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
final String myValue = request.getParameter("MyValue");
if (myValue != null && !myValue.isEmpty()) {
response.getWriter().write(myValue);
}
}
}
这很简单,对吧?
我已经尝试了很多 url 来查看我的结果,如下所示:
- http://localhost:8080/Servlet/servlet/Servlet
- http://localhost:8080/Servlet/servlet/Servlet?MyValue=Test
- http://127.0.0.1:8080/Servlet/servlet/Servlet
- http://127.0.0.1:8080/Servlet/servlet/Servlet?MyValue=Test
我的代码有问题还是我的 Eclipse 有问题?
谢谢