WEB开发网
开发学院WEB开发Jsp 用jsp将xml文件解析到网页显示,并把数据提交保存... 阅读

用jsp将xml文件解析到网页显示,并把数据提交保存到数据库

 2012-09-18 13:34:10 来源:WEB开发网   
核心提示:用户名:<input type="text" name="username" id="username" value="" size="20" />
用户名:<input type="text" name="username" id="username" value="" size="20" /> 
<input type="submit" value="提交" name="submit" /> 
<input type="reset" value="重置" name="reset" />
</form>
</body>
</html>
questionsave.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.*"%>
<%@ page import="com.mysql.jdbc.Driver"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.text.*"%>
<%@ page language="java" import="java.util.*"%>
<%
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_SAVES</title>
</head>
<body background="#123456">
<%
//驱动程序名
String driverName="com.mysql.jdbc.Driver";
//数据库用户名
String userName="root";
//密码
String userPasswd="520123412";
//数据库名
String dbName="xml";
//连接字符串
String url="jdbc:mysql://localhost:3306/"+dbName+"?user="+userName+"&password="+userPasswd+"&useUnicode=true&characterEncoding=UTF-8";
//加载驱动程序
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
request.setCharacterEncoding("UTF-8");
String question_id=request.getParameter("question_id");
String username=request.getParameter("username");
if(username!=null&&username!=""){
Map map=request.getParameterMap();
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
// Object val = entry.getValue();
if(((String)entry.getKey()).matches("sing_[0-99]_[0-99]")){
try{
String sing= request.getParameter((String)entry.getKey());
String[] str=((String)entry.getKey()).split("_");
//out.println("<p>"+str[0]+":"+str[1]+":"+str[2]+"</p>");

上一页  1 2 3 4 5  下一页

Tags:jsp xml 文件

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接