我有一个servlet和一个jsp页面,它显示了jsp页面上.txt文件(在我的本地机器上)的结果。我的问题是,当我点击jsp页面上的VIEWLOG按钮时,它应该在同一页面上显示结果。例如,我的VIEWLOG按钮位于名为view.jsp的页面上,我应该看到登录
http://localhost:8080/Project/view.jsp
但是它会在以下网址中显示结果
http://localhost:8080/project/status?showstatus=Status
。任何想法如何在VIEWLOG按钮所在的同一页面上获得结果。以下是代码段。
的Servlet
public class Status extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws
IOException {
try {
PrintWriter out = res.getWriter();
File file = new File("C:\\Debug\\logfile.txt");
if (file.exists()) {
BufferedReader input = new BufferedReader(new FileReader(file));
String line = "";
while ((line = input.readLine()) != null) {
out.println(line);
}
}
} catch (Throwable t) {
t.printStackTrace();
} finally {}
}
}
JSP:
<div id= "log" style="display:none;">
<FORM action="logfile" METHOD="GET">
<input type=submit
name=showLog
id=txtSubmit
value=ViewLOG />
</FORM>
</div>
WEB.XML:
<servlet>
<servlet-name>LogFile</servlet-name>
<servlet-class>com.san.plc.LogFile</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LogFile</servlet-name>
<url-pattern>/logfile</url-pattern>
</servlet-mapping>