error in web application

error in web application

In your application when i am trying to execute it from the below page

<%@ page language="java" import="java.util.*;"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE>Servlet Application</TITLE>

  <script language="javascript">
function editRecord(id){

    window.location.href="UserServlet/"+id; 
  }


  function deleteRecord(id){

    window.location.href="deleteUser/"+id; 
  }
</script>
 </HEAD>

 <BODY>
 <br>
<table align="center">

</table>
<br>
  <table width="600px"  align="center" style="background-color:#EDF6EA;border:1px solid #000000;">
 <tr><td colspan=9 align="center" height="10px"></td></tr>

    <tr><td colspan=9 align="center"><a href="addUser.jsp" style="font-weight:bold;color:#cc0000;">Add New User</a></td></tr>
<tr><td colspan=9 align="center" height="10px"></td></tr>
  <tr style="background-color:#7BA88B;font-weight:bold;">
     <td>User Id</td><td>UserName</td><td>First Name</td>
     <td>Last Name</td><td>City</td><td>Sate</td>
     <td>Country</td><td>Edit</td><td>Delete</td>
  </tr>
    <%
    String bgcolor="";
    int count=0;
    List viewList = new ArrayList();
    Iterator  viewItr;

    if(request.getAttribute("userList")!=null && request.getAttribute("userList")!="")
    {
        List userList =  (ArrayList)request.getAttribute("userList");
        Iterator itr = userList.iterator();

        while(itr.hasNext())
        {

            if(count%2==0)
            {
             bgcolor = "#C8E2D1";
            }
            else
            {

                bgcolor = "#EAF8EF";
            }

            viewList = (ArrayList)itr.next();
            int id = Integer.parseInt(viewList.get(0).toString());
            viewItr = viewList.iterator();
            %>
            <tr style="background-color:<%=bgcolor%>;">
            <%  
            while(viewItr.hasNext())
            {

                %>
                <td><%=viewItr.next()%></td>

                <%

            }
            count++;
            %>
            <td><input type="button" name="edit" value="Edit" style="background-color:#49743D;font-weight:bold;color:#ffffff;" onclick="editRecord(<%=id%>);" ></td>
                <td><input type="button" name="delete" style="background-color:#ff0000;font-weight:bold;;color:#ffffff;" value="Delete" onclick="deleteRecord(<%=id%>);"></td>
            </tr>
            <%
        }
    }
    if(count==0)
    {
        %>
        <tr><td colspan="9" align="center">&nbsp;</td></tr>
            <tr><td colspan="9" align="center">No Record Avaliable</td></tr>
        <%
    }
    %>
     <tr><td colspan=9 align="center" height="2px"></td></tr>
  </table>  
 </BODY>
</HTML>

when i click on edit button it is going on follwoing servlet

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.*;
import java.sql.*;
import java.util.*;

public class UserServlet extends HttpServlet{ 

   public void doGet(HttpServletRequest request, HttpServletResponse response)
                                   throws ServletException,IOException{
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            String str[] = request.getRequestURI().toString().split("/");

         int id = Integer.parseInt(str[3]);
            System.out.println("MySQL Connect Example.");
            Connection conn = null;
            String url = "jdbc:mysql://localhost:3306/";
            String dbName = "user_register";
            String driver = "com.mysql.jdbc.Driver";
            String userName = "root"; 
            String password = "root";

        //  out.println(request.getRequestURI());
            Statement st;
            try {
                Class.forName(driver).newInstance();
                conn = DriverManager.getConnection(url+dbName,userName,password);
                System.out.println("Connected to the database");


                ArrayList userList=null;
                String query = "select * from userregister where id="+id;
                System.out.println("query " + query);
                st = conn.createStatement();
                ResultSet  rs = st.executeQuery(query);


                while(rs.next())
                {

                  userList =new ArrayList();
                  userList.add(rs.getInt(1));
                  userList.add(rs.getString(2));
                  userList.add(rs.getString(4));
                  userList.add(rs.getString(5));
                  userList.add(rs.getString(6));
                  userList.add(rs.getString(7));
                  userList.add(rs.getString(8));

                }

                request.setAttribute("userList",userList);

                String nextJSP = "/editUser.jsp";
                RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
                dispatcher.forward(request,response);
                conn.close();
                System.out.println("Disconnected from database");
            } catch (Exception e) {
            e.printStackTrace();
            }
  }
}

but not redicting to editUser.jsp that is following

<%@ page language="java" import="java.util.*;"%>
<html>
<head>
</head>
<body>
<%!
int id;
String first_name="";
String last_name="";
String username="";
String city="";
String state="";
String country="";
List  userList=null;
%>

<%

if(request.getAttribute("userList")!=null && request.getAttribute("userList")!="")
{
        userList = (ArrayList)request.getAttribute("userList");
        id=Integer.parseInt(userList.get(0).toString());
        username=userList.get(1).toString();
        first_name=userList.get(2).toString();
        last_name=userList.get(3).toString();
        city=userList.get(4).toString();
        state=userList.get(5).toString();
        country=userList.get(6).toString();
        //out.println(id);
}
%>

<form name="userform" method="post" action="../editUser">
<br><br><br>
<table align="center" width="300px" style="background-color:#EDF6EA;border:1px solid #000000;">
<input type="hidden" name="id" value="<%=id%>">
<tr><td colspan=2 style="font-weight:bold;" align="center">Edit User</td></tr>
<tr><td colspan=2 align="center" height="10px"></td></tr>
    <tr>
        <td>First Name</td>
        <td><input type="text" name="first_name" value="<%=first_name%>"></td>
    </tr>
    <tr>
        <td>Last Name</td>
        <td><input type="text" name="last_name" value="<%=last_name%>"></td>
    </tr>
    <tr>
        <td>UserName</td>
        <td><input type="text" name="username" value="<%=username%>"></td>
    </tr>
    <tr>
        <td>Password</td>
        <td><input type="password" name="password" value=""></td>
    </tr>

    <tr>
        <td>City</td>
        <td><input type="text"  name="city" value="<%=city%>"></td>
    </tr>
    <tr>
        <td>State</td>
        <td><input type="text" name="state" value="<%=state%>"></td>
    </tr>
    <tr>
        <td>Country</td>
        <td><input type="text" name="country" value="<%=country%>"></td>
    </tr>

    <tr>
        <td></td>
        <td><input type="submit" name="Submit" value="Edit" style="background-color:#49743D;font-weight:bold;color:#ffffff;"></td>
    </tr>
    <tr><td colspan=2 align="center" height="10px"></td></tr>
</table>
</form>
</body>
</html>

please help me

View Answers

March 28, 2012 at 11:43 AM

We are providing you another application. Check it.

1)application.jsp:

<%@ page import="java.sql.*" %>
<html>
<head>
<script language="javascript">
function editRecord(id){
    var f=document.form;
    f.method="post";
    f.action='edit.jsp?id='+id;
    f.submit();
}
function deleteRecord(id){
    var f=document.form;
    f.method="post";
    f.action='delete.jsp?id='+id;
    f.submit();
}
</script>
</head>
<body>

<br><br>
<form method="post" name="form">
<table border="1">
<tr><th>Name</th><th>Address</th><th>Contact No</th><th>Email</th></tr>
<%
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "test";
String driver = "com.mysql.jdbc.Driver";
String userName ="root";
String password="root";

int sumcount=0;
Statement st;
try{
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+db,userName,password);
String query = "select * from employee";
st = con.createStatement();
ResultSet rs = st.executeQuery(query);
%>

<%
while(rs.next()){
%>
<tr><td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
<td><%=rs.getString(5)%></td>
<td><input type="button" name="edit" value="Edit" style="background-color:#49743D;font-weight:bold;color:#ffffff;" onclick="editRecord(<%=rs.getString(1)%>);" ></td>
<td><input type="button" name="delete" value="Delete" style="background-color:#ff0000;font-weight:bold;color:#ffffff;" onclick="deleteRecord(<%=rs.getString(1)%>);" ></td>
</tr>
<%
}
%>
<%
}
catch(Exception e){
e.printStackTrace();
}
%>
</table>
</form>
</body>
</html>

2)edit.jsp:

<%@page language="java"%>
<%@page import="java.sql.*"%>
<form method="post" action="update.jsp">
<table border="1">
<tr><th>Name</th><th>Address</th><th>Contact No</th><th>Email</th></tr>
<%
String id=request.getParameter("id");
int no=Integer.parseInt(id);
int sumcount=0;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
String query = "select * from employee where id='"+no+"'";
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
while(rs.next()){
%>
<tr>
<td><input type="text" name="name" value="<%=rs.getString("name")%>"></td>
<td><input type="text" name="address" value="<%=rs.getString("address")%>"></td>
<td><input type="text" name="contact" value="<%=rs.getInt("contactNo")%>"></td>
<td><input type="text" name="email" value="<%=rs.getString("email")%>"></td>
<td><input type="hidden" name="id" value="<%=rs.getString(1)%>"></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Update" style="background-color:#49743D;font-weight:bold;color:#ffffff;"></td>
</tr>
<%
}
}
catch(Exception e){}
%>
</table>
</form>

March 28, 2012 at 11:44 AM

continue..

3)update.jsp:

<%@page import="java.sql.*"%>

<%
String ide=request.getParameter("id");
int num=Integer.parseInt(ide);
String name=request.getParameter("name");
String address=request.getParameter("address");
int contact=Integer.parseInt(request.getParameter("contact"));
String email=request.getParameter("email");
try{
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root");
Statement st=null;
st=conn.createStatement();
st.executeUpdate("update employee set name='"+name+"',address='"+address+"',contactNo="+contact+",email='"+email+"' where id='"+num+"'");
response.sendRedirect("/examples/jsp/application.jsp");
}
catch(Exception e){
System.out.println(e);
    }
%>

4)delete.jsp:

<%@page import="java.sql.*"%>
<%

String id=request.getParameter("id");
int no=Integer.parseInt(id);
int sumcount=0;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st = conn.createStatement();
st.executeUpdate("DELETE FROM employee WHERE id = '"+no+"'");
response.sendRedirect("application.jsp");
}
catch(Exception e){}
%>

March 28, 2012 at 12:33 PM

thanx for your help but i need in servlet form as there is lots of other functionality which i have to embed in it..

can you help me with this..

just tell me the way i can extract data from the database in jsp form field but logic i have to apply to apply in servlets only for extraction of database fields and in jsp just i have to print the values extracted through servlet...









Related Tutorials/Questions & Answers:
error in web application
error in web application  In your application when i am trying to execute it from the below page <%@ page language="java" import="java.util....; We are providing you another application. Check it. 1)application.jsp
web application
web application  what is lazy loading in web based application
Advertisements
web application
web application  Dear friend, could u plz tell me wats difference bt web server,application server,container with thanks praveen
Web application
Web application  in web applications which file will execute first either servlet or jsp
web application
web application  Develop a web application to print back the inputs from the user(name, date of birth, address). The solution should have a JSP file which accepts the userâ??s name and sent to Servlets which puts the name
confused about an error in my web application deploying to Tomcat - Java Server Faces Questions
confused about an error in my web application deploying to Tomcat  Could any one please test this application and tell me what's the problem... org.apache.catalina.core.ApplicationContext log INFO: HTMLManager: start: Starting web application
application cntext file error
application cntext file error  i got an error when execute the file in junit using application context file org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file
Websphere application error - Hibernate
Websphere application error  i have received this following error [10/5/10 13:19:40:592 EDT] 00000043 SystemOut O java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl incompatible
web application to internet - JavaMail
web application to internet  how to connect my web application to internet
web application - WebSevices
web application  how to create a j2ee web application using java abstract class & interface
connecting to timesten in web application
connecting to timesten in web application  Please give me the steps connecting to timesten in web application. Am using jsp
Web application security - Security
Web application security  Hi, Expert how to hide url in webpage or fix the url in every web page in java.Please give any suggestion or idea
Directory structure of a web application
Directory structure of a web application   Explain the directory structure of a web application.    The directory structure of a web application consists of two parts. A private directory called WEB-INF.ADS
Web application - Spring
Web application  I need one simple complete web application example using springs with database connection,i saw ur demo but it is not succfient.can u send to [email protected] am a beginner
WEB APPLICATION IN JSP
WEB APPLICATION IN JSP  Can you help me with a JSP code which can search and update existing data in mysql database
java web application - Ant
tell me the steps to build and deploy a small web application on MyEclipse?(like... a directory structure for a Web application. a)Create a WEB-INF directory... deployment descriptor in the WEB-INF directory for the Web application. 5
log4j in web application
log4j in web application  Hi all, I am new to log4j. I want to use log4j in my web application. I need to write the debug,info,warn into a file... and how to get the logger object in web application. Thanks suresh
Java web Application
Java web Application  Hi! I have developed a java web application project using netbean IDE with glassfish server. My question is how to create a runnable file from this. How can we make it to a single file? I think it is war
Quartz in web-application
Quartz in web-application  As I am new to Quartz i don't know how to use it in web-application.I am able to run it in eclipse as a stand alone application i had tried out some example but am not able to succeed any help
Web application - business layer
Web application - business layer   Design your business layer to be stateless, which helps to reduce resource contention and increase... with a stateless Web application business layer. If you perform business
Web Application Common Architecture
Web Application Common Architecture  Hi, Any one tell me, while project constructing , how they architect it which means using some layers and specify importance of layers. And also best way to follow program flow
servlet question on web application
servlet question on web application   how to write a programg on the web application. create two modules like admin and customer. customer can registrate with user id and password. after finishing of his registration he'll get
Web application - JSP-Servlet
Web application   Helo can you please help me in knowing how to use jsp/servlets which allows users to post question in a forum so that other users can also view the question and respond to it.For instance your application here
web application security - Security
web application security  Hello, Experts how can i prevent that a copy url cannot run in same brower or different browser again .Please Suggest any idea i already check if a session is null then forwward a login page
Flex web application
Flex web application  Hi.... How can i develop web based applications in Flex? please give me the whole procedure so i can make web apps in flex..... Thanks
draw chart in web application
draw chart in web application  how to draw bar chat from the record store in database? i.e. draw the bar chart according to selected record
Spring Web MVC Application Error:ClassNotFoundException: DispatcherServlet on deploying
. DispatcherServlet I am discussing about the Spring Web MVC Application Error... for development of the application. But some times you may find some error while... the application on the Tomcat server. Such error occurs when you try to deploy
what is the difference between distributed application and web application?
what is the difference between distributed application and web application?  what is the difference between distributed application and web application
ssl comunication between a desktop application and a web application
ssl comunication between a desktop application and a web application  Hi Lusiano, I am trying to implement a ssl comunication between a desktop application and a web application. can you please share code with me. Please
Struts2 netbeans 6.5.1 application error - Struts
Struts2 netbeans 6.5.1 application error  i develop struts simple application in netbeans 6.5.1 but every time generate appache error Requested resources not available in so give me solution please any body
struts 2 Application starting error - Struts
struts 2 Application starting error  Hello Sir/Madam, Recently i... application which i have attached with name Struts2Application, but after deploying and starting the application the message was received like Message
HTS Web Application Framework
HTS Web Application Framework       The HTS Web Application Framework is a PHP and Javascript based framework designed to make simple web applications easy to design and implement
php mysql web application tutorial
php mysql web application tutorial  How to create a simple php mysql web application? Please post an example or tutorial
To publish jsp web application in intranet
To publish jsp web application in intranet  I am making web application in jsp with netbean. I want to publish this web application in LAN/Intranet.So by publishing web application it can be access through LAN/Intranet
Web application? - Java Interview Questions
Web application?  What is webapplication?  Hi friend, Any application that uses Web Technologies including web browsers, web servers and Internet protocols is called Web Application. A web application can
Why Struts in web Application - Struts
Why Struts in web Application  Hi Friends, why struts introduced in to web application. Plz dont send any links . Need main reason for implementing struts. Thanks Prakash
creating a friendly url for web application
creating a friendly url for web application  Hi all, I don't know how to create a friendly url for a web application. Please help me to resolve this problem. Thanks, Suresh
Quartz web application - Java Beginners
Quartz web application  Quartz is not firing jobs as per cron expression in java web application. I set the cron expression as 0/20 * * * * ? and when i load the web application it runs fine but its not firing the job after
ISAPI Filter Issue Error from Web Service ("Error:- InternetOpenUrl()")
ISAPI Filter Issue Error from Web Service  <p>I have writen MFC application for ISAPI filter which will authenticate and authorization... from web service.Error is "Error:- InternetOpenUrl().". This error is coming
Application Server and Web Server - WebSevices
Application Server and Web Server  General difference, Application Server and Web Server  Answer: A Web server handles the HTTP protocol. When the Web server receives an HTTP request, it responds with an HTTP response
Web based workflow application example?
Web based workflow application example?  Hello there, Can anyone please send a sample project which is a web-based java workflow application? If it is built using Spring, Struts or JSF Framework it would be wonderful. If you
java web application printing - WebSevices
java web application printing  i have a web-page with a table displayed containing report card of a class of students(visual web JSF APPLICATION created in netbeans 6.0) d problm i hv is i wnt to let dat page be converted
Error 500: WSWS3142E: Error: Could not find Web services engine. - WebSevices
Error Could not find Web services engine   Hi...: faultNode: faultDetail: {}:return code: 500 Error 500: WSWS3142E: Error: Could not find Web services engine. { http://xml.apache.org/axis
Error 500: WSWS3142E: Error: Could not find Web services engine. - WebSevices
Error 500 WSWS3142E Error Could not find Web services engine  Hi all, I am getting the following error.Error 500: WSWS3142E: Error: Could not find Web services engine. Please Help. Thanks in Advance
Introduction of Web Application
The application based on web is stored on a remote server and they can be accessed through web browser
ModuleNotFoundError: No module named 'weather.com-web-crawling-application'
ModuleNotFoundError: No module named 'weather.com-web-crawling-application...: ModuleNotFoundError: No module named 'weather.com-web-crawling-application' How...-application' error? Thanks   Hi, In your python environment you
how can i deploy web application on application server(weblogic,jboss)
how can i deploy web application on application server(weblogic,jboss)  I have develop wab application(jsp,servlet)and i can deploy my web application on tomcat easily but i want to deploy on application server(weblogic,jboss
Web Application Development in India, Web Application Development
Web Application Development in India Develop your Web Applications in India... customised web application development services to you. With our industry..., MySQL, ASP, PHP, etc our web application development services are always tuned
Web Application Development,Web Application Development India
Web Application Development Solutions India Web Application Development... of internet services worldwide and greater reliability on custom web application... web application development solutions that are reliable, scalable and robust
create web application using maven
In this section, you will learn to create a web application using maven

Ads