重定向的问题,可能是你的context root的问题,比如说你如果设置了你的应用的context root为/sample,也就是说不为/,那么你重定向的时候就要注意了,不能直接用绝对路径,
比如说你的jsp是在你的web应用的根目录,你可以用
response.sendRedirect(request.getContextPath() + "/sample.jsp"
其他问题,只能你自己看书了
比如说你的jsp是在你的web应用的根目录,你可以用
response.sendRedirect(request.getContextPath() + "/sample.jsp"
其他问题,只能你自己看书了
applications
+ - yourProject
+ - yourDefaultRoot
+ - *.jsp
+ - web-info
+ - web.xml
+ - classes
+ - packages
+ - *.class
如果是这样 ,在yourservlet.java中重导向一个页面, 则用response.sendRedirect("sample.jsp");
如果sample.jsp在yourDefaultRoot/ABC下 ,则用response.sendRedirect("ABC/sample.jsp");
Servlet存盘后必须行编译才能看到效果。不用设置,本来默认值就行了。
其中有一次调用servlet成功了,我的servlet文件的doPost方法中response.sendRedirct是这样的:response.sendRedirect("index.jsp")。
index.jsp和default.jsp在同一级目录下,但是也没有调用成功,也是报不能找到文件的错误。请各位指点,多谢先。
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>package.login</servlet-class> //servlet应放入一个包中
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
</web-app>
------------------------------------------------------
in .jsp:<form name="f1" method="POST" action="login">
记得结贴,不然你的信誉分会被扣
我也只能老是穿三角裤
;)