Home Discussion Discuss: JSP forward

  • Servlet jsp informationashwini October 3, 2011 at 5:18 PM

    In first frame it displays the rows of a table,it as radio button for each row,the fields in column it includes id,name,location.when i click radio button in one frame the contents should be displayed in another frame when fetched from database,it should display each field of row in the form of text box in second frame. please help me out

  • answerramprabhu February 8, 2012 at 9:20 AM

    package project.controller; import java.io.IOException; import java.sql.SQLException; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import project.bean.*; import project.model.*; protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("hi"); ProjectBean bean=new ProjectBean(); if(request.getParameter("action").equals("create")) { bean.setStudentname(request.getParameter("studentname")); System.out.println(request.getParameter("studentname")); bean.setDate(request.getParameter("date")); bean.setMark(Integer.parseInt(request.getParameter("mark"))); //System.out.println(+bean.getMark()); ProjectModel model=new ProjectModel(); try { bean=model.daoCallingMethod(bean); System.out.println("rohini"); request.setAttribute("message","Account created successfully"); RequestDispatcher redirect = getServletContext().getRequestDispatcher("/jsp/UI_page.jsp"); redirect.forward(request, response); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if(request.getParameter("action").equals("read")) { System.out.println("hello"); String studentname=request.getParameter("studentname"); System.out.println(studentname); ReadModel read=new ReadModel(); try { //request.setAttribute(studentname, bean); bean=read.readDaoCalling(studentname); request.setAttribute("studentname", bean); RequestDispatcher redirect = getServletContext().getRequestDispatcher("/jsp/display.jsp"); redirect.forward(request, response); System.out.println(studentname); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if(request.getParameter("action").equals("delete")) { bean.setStudentname(request.getParameter("studentname")); DeleteModel delete=new DeleteModel(); try { delete.deleteDaoCalling(bean); request.setAttribute("message","Deleted successfully"); RequestDispatcher redirect = getServletContext().getRequestDispatcher("/jsp/deletedisplay.jsp"); redirect.forward(request, response); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if(request.getParameter("action").equals("update")) { String studentname=request.getParameter("studentname"); System.out.println(studentname); request.setAttribute("studentname", bean); RequestDispatcher redirect = getServletContext().getRequestDispatcher("/jsp/updatepage.jsp"); redirect.forward(request, response); } else if(request.getParameter("action").equals("up")) { bean.setStudentname(request.getParameter("studentname")); System.out.println(request.getParameter("studentname")); bean.setDate(request.getParameter("date")); bean.setMark(Integer.parseInt(request.getParameter("mark"))); UpdateModel updatemodel=new UpdateModel(); try { updatemodel.updateDaoCalling(bean); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } package project.dao; import project.bean.*; import java.sql.*; public class DaoClass extends Connections { public ProjectBean daoMethod(ProjectBean bean) throws ClassNotFoundException, SQLException { Connection connection=getConnection(); Statement statement=connection.createStatement(); System.out.println("insert into studentproject values('"+bean.getStudentname()+"','"+bean.getDate()+"',"+bean.getMark()+")"); System.out.println("daoclass"); ResultSet rs=statement.executeQuery("insert into studentproject values('"+bean.getStudentname()+"','"+bean.getDate()+"',"+bean.getMark()+")"); return bean; } public ProjectBean readDaoMethod(String studentname) throws ClassNotFoundException, SQLException { Connection connection=getConnection(); Statement statement=connection.createStatement(); ProjectBean bean=new ProjectBean(); System.out.println("select * from studentproject where studentname='"+studentname+"'"); ResultSet rs1=statement.executeQuery("select * from studentproject where studentname='"+studentname+"'"); while(rs1.next()) { bean.setStudentname(rs1.getString("studentname")); bean.setDate(rs1.getString("Applydate")); bean.setMark(rs1.getInt("mark")); } return bean; } public int deleteDaoMethod(ProjectBean bean) throws ClassNotFoundException, SQLException { Connection connection=getConnection(); Statement statement=connection.createStatement(); ResultSet rs2=statement.executeQuery("delete from studentproject where studentname='"+bean.getStudentname()+"'"); return 1; } public void updateDaoMethod(ProjectBean bean) throws ClassNotFoundException, SQLException { Connection connection=getConnection(); Statement statement=connection.createStatement(); int result =statement.executeUpdate("update studentproject set studentname='"+bean.getStudentname()+"',applydate='"+bean.getDate()+"',mark="+bean.getMark()+""); if(result==1) { System.out.println("data updated"); } else { System.out.println("data not updated"); } } } package project.dao; import java.sql.*; /*class for connections*/ public class Connections { Connection con=null; /*method for open connection*/ public Connection getConnection() throws ClassNotFoundException, SQLException { /* * creating connection */ Class.forName("oracle.jdbc.OracleDriver"); String url= "jdbc:oracle:thin:@172.24.137.30:1521:ora10g"; con=DriverManager.getConnection(url,"e543820","REaqbsude"); return con; } /*method for close connection*/ public void closeConnection(Connection con) throws SQLException { /* * closing connection */ con.close(); } } CREATE MODEL: package project.model; import java.sql.SQLException; import project.bean.*; import project.dao.*; public class ProjectModel { public ProjectBean daoCallingMethod(ProjectBean bean) throws ClassNotFoundException, SQLException { DaoClass dao=new DaoClass(); bean=dao.daoMethod(bean); return bean; } } READ MODEL: package project.model; import java.sql.SQLException; import project.bean.*; import project.dao.DaoClass; public class ReadModel { public ProjectBean readDaoCalling(String studentname) throws ClassNotFoundException, SQLException { DaoClass dao=new DaoClass(); ProjectBean bean=new ProjectBean(); bean=dao.readDaoMethod(studentname); return bean; } } DELETE MODEL: package project.model; import java.sql.SQLException; import project.bean.ProjectBean; import project.dao.DaoClass; public class DeleteModel { public int deleteDaoCalling(ProjectBean bean) throws ClassNotFoundException, SQLException { DaoClass dao=new DaoClass(); int result=dao.deleteDaoMethod(bean); return result; } } package project.model; import java.sql.SQLException; import project.bean.*; import project.dao.DaoClass; public class UpdateModel { public void updateDaoCalling(ProjectBean bean) throws ClassNotFoundException, SQLException { DaoClass dao=new DaoClass(); dao.updateDaoMethod(bean); } }

Post your Comment



Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Related Articles
Struts Questions

Forward - Struts
Forward  Hi how to get the return value of execute() in Action class. we will write return mapping.findForward("success"); how to get the value of forward. Is there any method to get the which forward is executing 

JSP Servlet Questions

JSP Forward action
JSP Forward action  Jsp forward action tag examples 

JSP Interview Questions

Difference between forward and sendRedirect
to another jsp or servlet. sendRedirect() is more flexible than forward...Difference between forward and sendRedirect  What's the difference between forward and sendRedirect?   RequestDispatcher.forward 

JSP Interview Questions

jsp forward action tag
jsp forward action tag  Defined jsp forward action tag ?   ... application context as the forwarding JSP file. Syntax of forward action Tag: <jsp:forward page="{relativeURL | <%= expression %>}" /> <jsp:forward 

JSP Servlet Questions

jsp:forward tag ussage
jsp:forward tag ussage  can you give me example of how to use jsp:forward tag... i intend to call action class   Hi Friend, Please visit the following links: http://www.roseindia.net/jsp/jsp-forward-request.shtml 

JSP Servlet Questions

jsp forward not functioning
jsp forward not functioning  If the form in AddStudent.jsp...". Is it because of that, the jsp:forward is not forwarding... the student in the database (works OK) } %>}else{%> <jsp 

Struts Questions

forward error message in struts
forward error message in struts  how to forward the error message got in struts from one jsp to other jsp?   Hello Friend, Use <%@ page... to the specified jsp page. For more information, visit here Thanks 

JSP Servlet Questions

jsp:forward - JSP-Servlet
jsp:forward  Hi, I want check one condition if it is true the only I have forward it io jsp. My code is like this but it is not working please help...=formobject.formbeanvarable.value;(like /jsp/jspname.jsp) jsp name is captured from DB I 

Struts Questions

Browser Back/Forward - Struts
Browser Back/Forward  Hi, Greetings to all. I have developed a web application using Struts 2. Now, i want to enable browser back/forward/bookmarking in that. Can anyone post me some links/tutorial/examples or how to go 

Programming Tutorials

Forward a Jsp Page
Forward a Jsp Page In this example program we will show you how to use the <jsp:forward tag in your jsp program. The <jsp:forward tag is used... is not logged in you can forward the user on the login page. Here is the use of <jsp 

JSP Tutorials

JSP forward
JSP forward       This section illustrates you how you can use JSP forward action to forward to servlet. Create jsp Page: To create a jsp page,  following steps 

JSP Servlet Questions

jsp:forward tag usage and stntax
jsp:forward tag usage and stntax  jsp:forward tag usage and syntax with an example 

JSP Servlet Questions

Passing parameters in JSP using forward.
Passing parameters in JSP using forward.  If a page is forwarded to another page using jsp:forward, is it necessary that the page should be already............   Pass Parameters using jsp:forward 

Mobile Applications Questions

how send nsnotification to forward class
how send nsnotification to forward class   how to send nsnotification to a forward class? i am sending a nsnotification to a class which is not loaded yet. example,there is a class A,where i am creating a dictionary and posting 

Java Beginners

j2me- forward a video - Java Beginners
j2me- forward a video  hi friends, i have play a video using J2ME. but, i have unable to forward a video. does anybody know about it?? please help me.. thanks, regards, sakthi  Hi Friend, Please 

Struts Questions

Struts ForwardAction vs Forward tag in jsp - Struts
Struts ForwardAction vs Forward tag in jsp  difference between struts ForwardAction class and Forward tag in jsp 

JSP Servlet Questions

RequestDispatcher object, difference between include( ) and forward( ) method.
RequestDispatcher object, difference between include( ) and forward( ) method.  The RequestDispatcher object has two methods, include( ) and forward( ). What is the difference 

Programming Tutorials

This is Conditional Forward using EL
 

J2EE

@WebServlet RequestDispatcher Forward Example
@WebServlet RequestDispatcher Forward Example In this tutorial you will learn how forward to the another resources in the response. Sometimes it is required... will be required to forward directly to the another resource's/component 

JSP Servlet Questions

How to forward the control from one jsp to another?
How to forward the control from one jsp to another?  Hi... is not communicate with the Third JSP. I want forward the control from first jsp to second...-forward-request.shtml http://www.roseindia.net/jsp/jspforwardtoservlet.shtml Thanks 

JSP Servlet Questions

Should not logout after clicking the back/forward button
Should not logout after clicking the back/forward button  Hi all I have wrote a code for login now. User is able to login but after logging in when... if clicked the forward button user gets logged in..!! how can I solve this issue? What 

JSP Tutorials

Conditional Forward using EL
Conditional Forward using EL          We can forward one page to another jsp page...;).equals("")) {%> <jsp:forward page = " 

Struts Questions

How to validate a form in action class and forward errors to the jsp in struts?
How to validate a form in action class and forward errors to the jsp in struts?  How to validate a form in action class and forward errors to the jsp in struts 

JDBC

JDBC ResultSet Forward Type Example
JDBC ResultSet Forward Type Example: Through this ResultSet type the cursor only move forward in the result set and are non-scrollable. The following syntax are use for initialize the statement object to create a forward-only, read 

Struts Questions

How to disable browser back and forward button after logout [in struts2 or jsp]
How to disable browser back and forward button after logout [in struts2 or jsp]  How to disable browser back and forward button after logout [in struts2 or jsp] I am using window.history.forward(); function 

JSP Interview Questions

disable backward and forward buttons of the browsers - JSP-Interview Questions
disable backward and forward buttons of the browsers  Dear, Thanks for your last reply. I want if you help me to disable the backward of forward... to any website when i logout, i can not do forward or backward. In this way I 

General

Forward Log Records to Its Parent
Forward Log Records to Its Parent       This section describes how to forward log records... and this provides facility to forward log records to its parent. But it resumes 

Struts Questions

Struts Warnings ...About FormBeanConfig & about Cancel Forward - Struts
have created the following jsp pages 1)Index.jsp containning the link which...)WARNING: Unable to find 'cancel' forward. the contents of struts-config.xml 

JSP Interview Questions

disable backward and forward buttons of the browsers - JSP-Interview Questions
disable backward and forward buttons of the browsers  Dear, Please can you help me : I want to disable backward and forward buttons of the browsers (internet Explorere, Mozilla, Firefox, netscape and so). Is it possible 

Development process Questions

how to forward select query result to jsp page using struts action class
how to forward select query result to jsp page using struts action class  how to forward select query result to jsp page using struts action class 

DMCA.com