8

I have this jsp code where I am trying to edit information for the user my web page. I am new to jsp programming and I'm experiencing errors. Here is my code:

<%@page import="DatabaseTransactions.UserPhotosDataContext"%>
<%@page import="java.sql.ResultSet"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
            if (session.getAttribute("id") == null) {
                response.sendRedirect(request.getContextPath() + "/sign-in.jsp");
            }

            int userId = Integer.parseInt(session.getAttribute("id").toString());
            ResultSet userInfo = UserPhotosDataContext.getUserProfileInfo(userId);
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Edit Information</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <!-- Bootstrap -->
        <link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
        <link href="styles.css" rel="stylesheet">
    </head>

    <body class="bodybg">
        <jsp:include page="/navigation.jsp"/>
        <% userInfo.next();%>

        <div class="boxouter" style="margin-top:50px;">
            <h3 class="muted">Edit Information</h3>
            <!--- more code here---->

                <br><br>
                <form id="update-form" method="" action="">
                    <table style="margin:auto">
                        <tr>
                            <!--username-->
                            <td>
                                <label>Username <span id="uname-error" class="form-error"></span></label>
                                <input type="text" title="Use at least 6 characters"
                                       name="username" id="uname"
                                       value="<%=userInfo.getString("username")%>"
                                       placeholder="Username" disabled="true">
                            </td>

                            <!--email-->
                            <td>
                                <label>Email <span id="email-error" class="form-error"></span></label>
                                <input type="text"
                                       name="email" id="email"
                                       value="<%=userInfo.getString("email")%>"
                                       placeholder="Email" disabled="true">
                            </td>
                        </tr>

                        <!--- more code here---->

                    </table>

                    <center/>
                    <button class="btn btn-info" onclick="enablefields();" id="enablebtn" style="visibility:visible">Edit Information</button>

                    <a id="savelink" href="#" style="color:white;">
                        <button class="btn btn-info" id="savebtn" type="submit" style="visibility:hidden">Save</button>
                    </a>

                    <a href="#" style="color:white">
                        <button class="btn btn-info" id="deactivatebtn" style="visibility:visible">Deactivate Account</button>
                    </a>
                </form>
            </div>
        </div>


        <br><br>

        <!--- more code here---->

    <script type="text/javascript">
        function setValues() {
            if ("<%=userInfo.getString("gender")%>" == "Male")
            $('select option:contains("Male")').prop('selected',true);

            else if ("<%=userInfo.getString("gender")%>" == "Female")
            $('select option:contains("Female")').prop('selected',true);
        }

        window.onload = setValues;

    </script>

    <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrap.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrap-modal.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrap-popover.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrap-modalmanager.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/editinfo.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/holder.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/logout.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrap-dropdown.js"></script>
</body>
</html>

When I run it, I get this error:

org.apache.jasper.JasperException: An exception occurred processing JSP page /editinfo.jsp at line 61

Line 61 is:

value="<%=userInfo.getString("email")%>"

I remove this line and it works perfectly fine (but I need this to get the value). When I keep line 61 and try to remove this:

value="<%=userInfo.getString("username")%>"

which is at line 52 of my page, it still doesn't work.

I also replace line 52 to line 61 and it works.

I also get these errors:

javax.servlet.ServletException: java.sql.SQLException: Column 'email' not found. java.sql.SQLException: Column 'email' not found.

But I'm 100% sure that my database has an email column. Also, when I try this for the other columns of my database, it gives back the same error. It only works if it is "username" column. Please help me. How do I fix this?

achll
  • 153
  • 1
  • 4
  • 12
  • The problem is regarding sql exception you got. Try to test this line of code userInfo.getString("username") outside of your jsp, and check if works. – Ioan Aug 08 '13 at 09:36
  • @loan - I tried to display an alert and it works. – achll Aug 08 '13 at 09:44
  • @Prabhaker what do you mean? I have it here:ResultSet userInfo = UserPhotosDataContext.getUserProfileInfo(userId); – achll Aug 08 '13 at 09:44
  • It's still not working. Please help :( – achll Aug 08 '13 at 09:48
  • value="<%=userInfo.getString("username")%>" if this is working for you then you must check your email type is it varchar or a possible string format – user2408578 Aug 08 '13 at 09:58
  • @user2408578 the format is varchar. but it still doesn't work – achll Aug 08 '13 at 10:15
  • If you can post "getUserProfileInfo(id)" method here or query that you are firing in this method, – user2408578 Aug 08 '13 at 10:32
  • Look at here http://stackoverflow.com/questions/2322031/why-did-servlet-service-for-servlet-jsp-throw-this-exception – Anurag_BEHS Dec 18 '15 at 18:53

5 Answers5

0

Try the following way:

value='<%=userInfo.getString("email")%>'

Does that fix the problem? Actually single quotes might cause problems

Cimbali
  • 11,012
  • 1
  • 39
  • 68
user2408578
  • 464
  • 1
  • 4
  • 13
0

the expression tags means <%= ....... >

has take semicolon (;) at the end of expression.

value='<%= userInfo.getString("email") ; %>'

I hope it will work ,please try this.

Mohsin Shaikh
  • 494
  • 1
  • 4
  • 11
0

Try:

value "<%= userInfo.getString("email") %>"

or

value <%= userInfo.getString("email") %>

No ; when you use the <%= %> expression.

Also, I think you don't need two = signs, but only the one inside <%= %>.

Don Cruickshank
  • 5,641
  • 6
  • 48
  • 48
Yitong
  • 1
0

since the original error is java.sql.SQLException forget about JSP errors for now.

Write some tests for UserPhotosDataContext.getUserProfileInfo(userId) so you can debug the ResultSet.

You're sure email is in the table - are you sure it's in the sql query ?

Also, check that you are retrieving the columns from the ResultSet in the order they appear in the ResultSet.

For example, if your ResultSet is:

email, username, ...

then trying to access email after you have already accessed username MIGHT not work.

I say MIGHT because this is probably specific to whatever database driver you are using - I came across this when using Sybase.

user1373164
  • 428
  • 4
  • 14
-1

You need to try, (if you are using MySQL as DB) "MySQL Connector" jar file, add or (copy) to in your server lib folder.

uttam
  • 1