我必须显示一个在 index.jsp 中编码的页面,在这个页面中我使用了 onload 提交
<script type="text/javascript">
function myfunc () {
var frm = document.getElementById("my_form");
frm.submit();
}
window.onload = myfunc;
</script>
<form id="my_form" action="tempmonitor" method="post">
以上是我的jsp代码,我在这个页面上打印了你好。但是当我点击 URL localhost:8090/tempmonitoringsystem/index.jsp。它显示 nanosec den 的 index.jsp 转到以下 URL localhost:8090/tempmonitoringsystem/tempmonitor,我不知道它重定向到哪里。我正在附加我的 servlet 代码以及 xml 代码。
TempMonitorServlet.java
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
System.out.println("hello world");
String path = "E:\\";
String files;
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++)
{
if (listOfFiles[i].isFile())
{
files = listOfFiles[i].getName();
if (files.endsWith(".txt") || files.endsWith(".TXT"))
{
System.out.println(files);
ReadingFromFile read_file = new ReadingFromFile();
String last_line_from_file = read_file.read(files) ;
System.out.println("\n"+last_line_from_file);
if(last_line_from_file != null)
{
drawImage(req,resp ,last_line_from_file,files) ;
}
}
}
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>ZigbeeRest</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
<servlet>
<servlet-name>tempmonitor</servlet-name>
<servlet-class>tempmonitor.TempMonitorServlet
</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.restful.Zigbee.services.ZigbeeApplication</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>tempmonitor</servlet-name>
<url-pattern>/tempmonitor</url-pattern>
</servlet-mapping>