Jsp Page session vaiable to java class and vise versa

Hi to all,

I am new to jsp, i have to programs, one jsp page and another java class. in jsp page i get the user data from html form and put the id in session. here i have to call the session vaiable to my java class where it (variable)initialize a file name.

and same i have to call the java class to jsp page which insert statements to sql server,

Please Help Me.

[389 byte] By [kurra99a] at [2007-11-27 1:57:10]
# 1
I don't see a specific coding question/problem? I only see some requirements.Please elaborate. Or don't you just know where to start? If so, start here: http://java.sun.com/javaee/5/docs/tutorial/doc/
BalusCa at 2007-7-12 1:32:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thank you,Here is my code in jsp pagesession.setAttribute("ID");this value i have to call to a java class studentInfo()String Stufile="c://"+ID+".txt";i am not able to get the session variable to java class
kurra99a at 2007-7-12 1:32:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
> i am not able to get the session variable to java classInside the ServletContext the HttpSession is just available by ServletContext#getSession().
BalusCa at 2007-7-12 1:32:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Can You please tell me how to declear it. to put it in my code
kurra99a at 2007-7-12 1:32:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Excuse, it should be HttpServletRequest#getSession().I need more coffee :P
BalusCa at 2007-7-12 1:32:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

//My Java Class file

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import javax.servlet.http.HttpSession;

import java.sql.Statement;

public class StuInfo extends Object {

//main method begins execution of Java application

public static void main (String args[]){

String StuFile = "C://"+iD+".txt";// Here i have to get the session varaible.(ID)

try {

}

In my jsp Page i initilized session as

session.setAttribute("ID",StuId);

I am not able to understand where i have to declear the HTTPSession#getAttribute("ID");

kurra99a at 2007-7-12 1:32:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
Which framework are you using then? I assumed that you was using servlets. How are you calling this class from JSP? I see a main method which is odd.
BalusCa at 2007-7-12 1:32:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
That is problem. I just wrote individual java class files. and jsp pages. I dont know the correct procedure how to call the java class in my jsp page and jsp data to java class.Please guide me in doing this task.
kurra99a at 2007-7-12 1:32:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

Something like:MyClass myClass = new MyClass();

myClass.doSomething(session.getAttribute("name"));

?

Anyway: start off with the Java EE tutorial: http://java.sun.com/javaee/5/docs/tutorial/doc/

Servlets starts at chapter 3. JavaBeans starts halfway chapter 4.

BalusCa at 2007-7-12 1:32:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
Thank You,I WIll refer to the mentioned Manual and come back.
kurra99a at 2007-7-12 1:32:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...