| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2758 人关注过本帖
标题:jsp 用 AJAX 跟 jQeury 的问题
只看楼主 加入收藏
经哥
Rank: 3Rank: 3
来 自:代码空间
等 级:论坛游侠
威 望:1
帖 子:289
专家分:124
注 册:2012-9-8
结帖率:91.8%
收藏
已结贴  问题点数:20 回复次数:5 
jsp 用 AJAX 跟 jQeury 的问题
程序代码:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
    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>
<title>doreg.jsp</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
         
<script type="text/javascript" src="../script/jquery-1.7.1.js"></script>
<script type="text/javascript">
    $(function(){
        $("input[name=button]").click(function(){
            var username = $("input[name=username]").val();
            var sex = $("input[name=sex]:checked").val();
            var age = $("input[name=age]").val();
            var important = $("select[name=important] option:selected").val();
            var tag = $("input[name=tag]").val();       
            var data={
                "username":username,
                "sex":sex,
                "age":age,
                "important":important,
                "tag":tag
            };
            $.post("JSdoreg.jsp",data,function(data,state){
            if(status == "success"){
                alert(data.msg);
                window.location.href="register.jsp";
            }else{
                alert("添加失败!");
            }
            },"json");
        });
    });
</script>
</head>
<body>
    <form  style="text-align:center;" method="post">
        用户id:<input type="text" name="userid" id="userid" >
            <span id="info"></span><br />
        用户名:<input type="text" name="username"><br />
        性别:<input type="radio" name="sex" value="1">男
            <input type="radio" name="sex" value="2">女 <br />
        年龄:<input type="text" name="age"><br />
        等级:<select name="important">
                <option>重要的</option>
                <option>次要的</option>
                <option selected="selected">忽略的</option>
            </select> <br />
        标签:<input type="text" name="tag"><br />
        <input type="button" name="button" value="确定">
    </form>
</body>
</html>
搜索更多相关主题的帖子: content PUBLIC title 
2014-09-17 22:06
经哥
Rank: 3Rank: 3
来 自:代码空间
等 级:论坛游侠
威 望:1
帖 子:289
专家分:124
注 册:2012-9-8
收藏
得分:0 
程序代码:
<%@ page language="java"
    import="java.util.*,javax.naming.Context,javax.naming.InitialContext,javax.sql.DataSource,java.sql.*"
    pageEncoding="utf-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<jsp:useBean id="user" class="com.joker.bean.UserBean" scope="page"></jsp:useBean>
<jsp:setProperty property="*" name="user" />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'doreg.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
</head>
<body>

    <%--
        String ueridStr = (String) request.getParameter("userid");
        String username = (String) request.getParameter("username");
        String sexStr = (String) request.getParameter("sex");
        String ageStr = (String) request.getParameter("age");
        String important = (String) request.getParameter("important");
        String tag = (String) request.getParameter("tag");
        pageContext.setAttribute("ueridStr", ueridStr);
        pageContext.setAttribute("username", username);
        pageContext.setAttribute("sexStr", sexStr);
        pageContext.setAttribute("ageStr", ageStr);
        pageContext.setAttribute("important", important);
        pageContext.setAttribute("tag", tag);
        --%>

        <%
        String userId = user.getUserid();
        int userid = (int) Integer.parseInt(userId);
        //pageContext.setAttribute("userid", userid);
        String username = user.getUsername();
        int sex = user.getSex();
        //String age = user.getAge();
        int age = (int) Integer.parseInt(user.getAge());
        String important = user.getImportant();
        String tag = user.getTag();
   
        pageContext.setAttribute("userid", userid);
        pageContext.setAttribute("username", username);
        pageContext.setAttribute("sex", sex);
        pageContext.setAttribute("age", age);
        pageContext.setAttribute("important", important);
        pageContext.setAttribute("tag",tag);
   
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Context ctx = new InitialContext();
        DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/test");
        Connection conn = ds.getConnection();
        PreparedStatement ps= conn.prepareStatement("insert into work values(?,?,?,?,?,?)");
        ps.setInt(1,userid);
        ps.setString(2,username);
        ps.setInt(3,sex);
        ps.setInt(4,age);
        ps.setString(5,important);
        ps.setString(6,tag);
        ps.executeUpdate();
        ps.close();
        conn.close();
        ctx.close();
        out.println("{\"status\":1,\"msg\":\"success\"}");
    %>
</body>
</html>

我只是个演员,还是业余的!!
2014-09-17 22:06
经哥
Rank: 3Rank: 3
来 自:代码空间
等 级:论坛游侠
威 望:1
帖 子:289
专家分:124
注 册:2012-9-8
收藏
得分:0 
错误异常
2014-9-17 22:00:59 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jsp threw exception
java.lang.NumberFormatException: null
    at java.lang.Integer.parseInt(Integer.java:415)
    at java.lang.Integer.parseInt(Integer.java:497)
    at org.apache.jsp.user.JSdoreg_jsp._jspService(JSdoreg_jsp.java:108)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
    at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617)
    at org.apache.tomcat.(AprEndpoint.java:1774)
    at java.lang.Thread.run(Thread.java:619)

我只是个演员,还是业余的!!
2014-09-17 22:07
经哥
Rank: 3Rank: 3
来 自:代码空间
等 级:论坛游侠
威 望:1
帖 子:289
专家分:124
注 册:2012-9-8
收藏
得分:0 
大神都去哪了

我只是个演员,还是业余的!!
2014-09-18 16:17
经哥
Rank: 3Rank: 3
来 自:代码空间
等 级:论坛游侠
威 望:1
帖 子:289
专家分:124
注 册:2012-9-8
收藏
得分:0 
大神啊!!

我只是个演员,还是业余的!!
2014-09-19 17:23
hhwz
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:87
帖 子:687
专家分:4502
注 册:2011-5-22
收藏
得分:20 
不是空指针吗
2014-09-19 19:22
快速回复:jsp 用 AJAX 跟 jQeury 的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027314 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved