我有以下问题:
我有一个带有以下代码的 JSP 文件:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Mehr Tutorials gibt es auf: http://www.itblogging.de</title>
</head>
<body>
Um eine Lieferung aufzugeben bitte die folgenden Daten ausfüllen:<br />
<hr />
<form method="GET" name="Lieferung" action="LoginCheck">
Kennzeichnung<br />
<input type="text" name="ID" /><br />
Abholpunkt<br />
<input type="text" name="Start" /><br />
Lieferpunkt<br />
<input type="text" name="End" /><br />
Kontaktmail<br />
<input type="text" name="Mail" /><br />
Link<br />
<input type="text" name="Link" /><br />
<input type="submit" value="Lieferung aufgeben" />
<input type="reset" value="reset" />
</form>
</body>
</html>
当我单击提交按钮时,一个 servlet 会创建以下类的对象:
package servlet;
public class Lieferinhalt {
String link = "";
String ID ="";
String von ="";
String nach ="";
String mail ="";
void setLink(String a) {
this.link = a;
}
void setID(String a) {
this.ID= a;
}
void setVon(String a) {
this.von = a;
}
void setNach(String a) {
this.nach = a;
}
void setMail(String a) {
this.mail = a;
}
}
然后,servlet 将 JSP 文件中的信息放入该类的对象中,并且为了测试,它创建了一个 HTML 代码来说明对象的值。它看起来像这样:
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LoginCheck extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String id = request.getParameter("ID");
String start = request.getParameter("Start");
String end = request.getParameter("End");
String mail = request.getParameter("Mail");
String link = request.getParameter("Link");
Lieferinhalt a = new Lieferinhalt();
String docType =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 "+
"Transitional//EN\">\n";
a.setID(id);
a.setVon(start);
a.setNach(end);
a.setMail(mail);
a.setLink(link);
out.println(docType + "<HTML>\n"+
"<HEAD><TITLE>HalloWelt</TITLE></HEAD>\n"+
"<BODY BGCOLOR=\"#FDF5E6\""+
"<H1>Servlet funktioniert!</H1>"+ "<br />" +
"Die ID war: " + a.ID + "<br />" +
"Der Startpunkt war: " + a.von + "<br />" +
"Der Endpunkt war: " + a.nach + "<br />" +
"Die Mail war: " + a.mail + "<br />" +
"Der Link war: " + a.link + "<br />" +
"</BODY></HTML>");
}
}
我想要做的是将此对象保存在数据库之类的东西中。我们不允许使用 SQL 和其他数据库语言。我想到了像永久 ArrayList 之类的东西。那可能吗?还是有其他/更好的方法?它们是如何工作的?
谢谢!