开发者

load value to a textbox dynamically

Sir, I've a combobox whose id is "courseid" in my jsp page removeCourse.jsp. When i change the value of the combobox i want the corresponding coursename will be displayed in a textbox whose id is cname. For this purpose i've make a servlet which returns the corresponding result with a resultset rs. I write the code as below Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection con=DriverManager.getConnection("jdbc:mysql://localhost/online_exam?"+"user=root&password=pass"); Statement stmt=con.createStatement();

        courseid=request.getParameter("courseid");
        ResultSet rs=stmt.executeQuery("select course_name from course where course_id='"+courseid+"'");
        setCourseName s=new setCourseName();
        s.setCourseName(cname);
        while(rs.next())
        {
            cname=rs.getNString("course_name");
            s.setCourseName(cname);

        }
        //response.sendRedirect("http://localhost:8080/ONLINEEXAMINATION/removeCourse2.jsp");
        request.setAttribute("courseName",cname);
        request.getRequestDispatcher("http://localhost:8080/ONLINEEXAMINATION/removeCourse.jsp").forward(request, response);

and then in the jsp page i write the code to assign the value as given below

But it doesn't display the coursename in the textbox when i select a courseid from the com开发者_如何学运维bobox. Can you say where is the problem? In the web.xml i also write the following searchCname /removeCourse


Instead of using

request.getRequestDispatcher("http://localhost:8080/ONLINEEXAMINATION/removeCourse.jsp").forward(request, response);

you have to change the path to

request.getRequestDispatcher("/removeCourse.jsp").forward(request, response);

The url you are providing is wrong.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜