用jsp将xml文件解析到网页显示,并把数据提交保存到数据库(2)
来源:未知 责任编辑:责任编辑 发表时间:2014-05-20 18:33 点击:次
</answer>
</question>
<question id="6" type="3">
<title><![CDATA[你怎样评价自己?]]></title>
<answer>
<it><![CDATA[例如,我是一个很牛逼的人!]]></it>
</answer>
</question>
</questions>
questions.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="javax.xml.parsers.*,org.w3c.dom.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>QUESTION</title>
</head>
<body bgcolor="#79CDCD">
<%
DocumentBuilderFactory questionDBF=DocumentBuilderFactory.newInstance();
DocumentBuilder questionDB = questionDBF.newDocumentBuilder();
Document document=questionDB.parse(pageContext.getServletContext().getResourceAsStream ("question.xml"));
Element element = document.getDocumentElement();
NodeList questions = element.getElementsByTagName("question");
%>
<form name="questionform" id="questionform" action="questionsave.jsp" method="POST">
<%
out.println("<input type="+"\"hidden\""+" name="+"\"question_id\""+" value="+"\""+element.getAttribute("id")+"\""+"/>");
for (int i = 0; i < questions.getLength(); i++) {
Element questionElement = (Element) questions.item(i);
if(Integer.parseInt(questionElement.getAttribute("type"))==1){
相关新闻>>
- 发表评论
-
- 最新评论 更多>>