import javax.servlet.*;
import javax.servlet.http.*;
public class tz extends HttpServlet
{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException
{
try{
String carname = request.getParameter("cars");
ServletContext sc = getServletContext();
if(carname.length() !=0){
sc.getRequestDispatcher("/thanks.html")
.forward(request, response);
}
else{
sc.getRequestDispatcher("/error.htm")
.forward(request, response);
}
}
catch(Exception e){
e.printStackTrace();
}
}
}
上面是转交请求的程序码..
thanks.html 的程序
<html>
<head><title>WELCome</title></head>
<body><center>
<h2>ERROR<h2>
Error<br/>
</center></body>
</html>
error.html 的程序
<html>
<head><title>WELCome</title></head>
<body><center>
<h2>THANKS<h2>
Thanks<br/>
</center></body>
</html>
我是刚接触Servlet的新手.. 想请教各位前辈, 这是我照着书上操作的程序码, 编译成功了!
但是进入网页后操作却一直显示[附图]那样的画面, 请教各位前辈我在哪个环节出错了..
还是有什么没有设定好.. 谢谢各位前辈!!