總體而言,您的方法非常笨拙,您可以稍微修改它。
I have an HTML page which posts its form data (DB credentials) to a servlet.
In the servlet, I create a connection using the credentials.
建立連接。檢查連接是否建立
Now I want to display an HTML page which will accept the details of a record to be entered.
I want to then retrieve this data and enter it into the DB
如果確定它重定向到你需要創建一個HTML頁面來接受來自用戶的輸入,並將其張貼到servlet第二HTML頁面。你甚至可以將它發佈到同一個servlet和使用輸入字段處理它們,你甚至可以將它發佈到另一個servlet
Will this second post start a new servlet instance?
沒有Web容器犯規創建一個新的對象,每次,而這股同樣的實例,直到應用程序正在運行
而我不知道你爲什麼要顯示servlet內的html內容。 JSP僅用於此目的。
希望它有幫助!