1
我有以下問題:持久性的Servlet中沒有數據庫
我有下面的代碼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代碼,它說T的值他反對。它看起來像這樣:
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之類的東西。那可能嗎?或者還有其他更好的方法嗎?他們如何工作?
謝謝!
您的意思是? http://www.rgagnon.com/javadetails/java-0075.html –
你能推薦一個好的教程嗎?我找不到任何有用的東西:/ –
看看JAX-B:http://jaxb.java.net/tutorial/ – duffymo