Results 1 to 5 of 5
  1. #1
    jhen is offline Member
    Join Date
    Nov 2008
    Posts
    12
    Rep Power
    0

    Default creating a session

    :mad:whta are the lines of codes needs to function the java session thatI have made?

    Anyone there? this is urgent>>>
    tnx

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Can you explain your question more clearly. I don't think anyone can understand what you exactly want.

    Keep in mind that this is a forum, not a code bank lol.

  3. #3
    jhen is offline Member
    Join Date
    Nov 2008
    Posts
    12
    Rep Power
    0

    Default session...

    awkei...,

    this a my web page, for instance...these are the fields that nids to be filled up..

    Student information

    Student No:

    First Name:

    Middle Initial:

    Last Name:

    City:

    Province:

    then there is a command button here named "submit".. when i click this submit button, automatically, the inputted information above will be displayed on the next page...

    how will i do that? I have here the codes but it's not working...

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  5. #5
    jhen is offline Member
    Join Date
    Nov 2008
    Posts
    12
    Rep Power
    0

    Default still session>>>

    there's no error... the problem is when i click the submit button, it doesn't turn on the next page...


    here is the code, i used java servlet for creating session...


    package myBean;

    import java.io.IOException;
    import java.sql.SQLException;

    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;


    public class MyServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {

    HttpSession session;
    private MyBeanssss sessionbean;
    RequestDispatcher dispatcher;
    private String go;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
    doPost(request, response);
    }


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
    session=request.getSession(true);
    if(session!=null)
    {
    sessionbean=(MyBeanssss)session.getAttribute("bean _id");
    go=(String)session.getAttribute("1stPage.jsp");
    }
    if (sessionbean!=null)
    {
    if(request.getParameter("btnSubmit")!=null){
    sessionbean.setStudentNo(request.getParameter("stu dentNo")!=null? request.getParameter("StudentNo"): "");
    sessionbean.setFname(request.getParameter("Fname") !=null? request.getParameter("Fname"): "");
    sessionbean.setMI(request.getParameter("MI")!=null ? request.getParameter("MI"):"");
    sessionbean.setLName(request.getParameter("LName") !=null? request.getParameter("LName"):"");
    sessionbean.setCity(request.getParameter("City")!= null? request.getParameter("City"):"");
    sessionbean.setProvince(request.getParameter("Prov ince")!=null? request.getParameter("Province"):"");
    go="2ndPage.jsp";
    }
    else if (request.getParameter("btnBack")!=null){
    go="1stpage";
    }
    else if(request.getParameter("Save")!=null){
    doGetFormEntries(request);
    try
    {
    sessionbean.doSave();
    }catch (SQLException e)
    {
    e.printStackTrace();
    }
    go="1stPage.jsp";
    }
    else if(sessionbean!=null)
    {
    if (request.getParameter("btnCancel")!=null){
    sessionbean.setStudentNo("");
    sessionbean.setFname("");
    sessionbean.setMI("");
    sessionbean.setLName("");
    sessionbean.setCity("");
    sessionbean.setProvince("");
    go="1stpage.jsp";

    }
    else
    {
    sessionbean=new MyBeanssss();
    sessionbean.setStudentNo("");
    sessionbean.setFname("");
    sessionbean.setMI("");
    sessionbean.setLName("");
    sessionbean.setCity("");
    sessionbean.setProvince("");
    }
    }
    }
    session.setAttribute("bean_id", sessionbean);
    session.setAttribute("1stPage.jsp", go);

    dispatcher=request.getRequestDispatcher(go);
    dispatcher.forward(request,response);
    }



    private void doGetFormEntries(HttpServletRequest request)
    {
    sessionbean.setStudentNo(request.getParameter("Stu dentNo"));
    sessionbean.setFname(request.getParameter("fname") );
    sessionbean.setMI(request.getParameter("MI"));
    sessionbean.setLName(request.getParameter("lname") );
    sessionbean.setCity(request.getParameter("city"));
    sessionbean.setProvince(request.getParameter("prov ince"));
    }






    }



    this is the bean but i think there,s no problem here:

    package myBean;


    import java.sql.ResultSet;
    import java.sql.CallableStatement;
    import java.sql.SQLException;
    import java.sql.Connection;

    import my_common.*;
    import my_common.DbConnector;


    public class MyBeanssss
    {
    private Connection conn;
    private CallableStatement cstmnt;

    private String currentPage;

    private String StudentNo="";
    private String Fname="";
    private String MI="";
    private String LName="";
    private String City="";
    private String Province="";


    public void doSave() throws SQLException
    {
    String sql= "{call sample_proc (?,?,?,?,?,?)}";//connection with database

    conn=my_common.DbConnector.getConnection();
    cstmnt = conn.prepareCall(sql);

    cstmnt.setString(1, this.getStudentNo());
    cstmnt.setString(2,this.getFname());
    cstmnt.setString(3,this.getMI());
    cstmnt.setString(4,this.getLName());
    cstmnt.setString(5,this.getCity());
    cstmnt.setString(6,this.getProvince());

    cstmnt.executeUpdate();
    }

    public String getStudentNo() {
    return StudentNo;
    }
    public void setStudentNo(String studentNo) {
    StudentNo = studentNo;
    }

    public String getCity() {
    return City;
    }
    public void setCity(String city) {
    City = city;
    }
    public String getFname() {
    return Fname;
    }
    public void setFname(String fname) {
    Fname = fname;
    }
    public String getLName() {
    return LName;
    }
    public void setLName(String name) {
    LName = name;
    }
    public String getMI() {
    return MI;
    }
    public void setMI(String mi) {
    MI = mi;
    }
    public String getProvince() {
    return Province;
    }
    public void setProvince(String province) {
    Province = province;
    }

    public Connection getConn() {
    return conn;
    }
    public void setConn(Connection conn) {
    this.conn = conn;
    }
    public CallableStatement getCstmnt() {
    return cstmnt;
    }
    public void setCstmnt(CallableStatement cstmnt) {
    this.cstmnt = cstmnt;
    }

    public String getCurrentPage() {
    return currentPage;
    }
    public void setCurrentPage(String currentPage) {
    this.currentPage = currentPage;
    }


    }

Similar Threads

  1. Session and request in JSF
    By felixtfelix in forum Web Frameworks
    Replies: 0
    Last Post: 05-08-2008, 05:10 PM
  2. session
    By jm_it04 in forum AWT / Swing
    Replies: 0
    Last Post: 03-04-2008, 11:32 AM
  3. Creating a Session Ejb in NetBeans IDE
    By JavaForums in forum NetBeans
    Replies: 0
    Last Post: 07-30-2007, 11:13 PM
  4. Use session
    By Eric in forum Java Servlet
    Replies: 1
    Last Post: 07-05-2007, 08:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •