You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by ibozo <ib...@ku.edu.tr> on 2007/06/01 23:53:39 UTC

Tomcat session varibale

Hello all, 
   I have created a file of servlet pages that publish those pages in Tomcat
6. I have a log in page, programmed by servlet and also another page that
activates the application acording to the given parameters by serching
webserver. I should use the taken variable on the log in page in another
servlet page. I tried to create a session variable and use it inside the
other web servlet. However I am unable to suceed... Can you help me as soon
as possible..
Best, 
ilker
-- 
View this message in context: http://www.nabble.com/Tomcat-session-varibale-tf3854667.html#a10921127
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Tomcat 6 Manager App question (Memory usage)

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Jacob Rhoden [mailto:jacob@rhoden.id.au] 
> Subject: Tomcat 6 Manager App question (Memory usage)
> 
> Free memory: 0.86 MB Total memory: 9.35 MB Max memory: 63.56 MB
> 
> What is the difference between total memory and max memory.

Total memory is the current size of the heap (somewhere between the -Xms
and -Xmx values); max memory is the upper bound on heap size (-Xmx).
Free memory is the amount of total memory that is not currently
allocated to objects.

A list of useful references:
http://java.sun.com/javase/technologies/hotspot/gc/index.jsp

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Tomcat 6 Manager App question (Memory usage)

Posted by Jacob Rhoden <ja...@rhoden.id.au>.
Hi,

The manager application status page reports the following regarding 
memory usage:

Free memory: 0.86 MB Total memory: 9.35 MB Max memory: 63.56 MB

I am confused about what this means. What is the difference between 
total memory and max memory. Is the free memory what is left of total 
memory, or maximum memory?

Best Regards,
Jacob

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat Security - Disable the http connector

Posted by Jacob Rhoden <ja...@rhoden.id.au>.
Pid wrote:
> Jacob Rhoden wrote:
>> If I only allow connections to tomcat through apache (mod_jk), is it 
>> ok then to turn off the the  http connector...
>
> Yes, just comment it out and restart.
I have already done it. Thanks! I was just worried there would be some 
un-intended repercussions.

Best Regards,
Jacob

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat Security - Disable the http connector

Posted by Pid <p...@pidster.com>.
Jacob Rhoden wrote:
> Hi,
> 
> If I only allow connections to tomcat through apache (mod_jk), is it ok 
> then to turn off the the  http connector, ie (for example in tomcat 6)
> 
>    <Connector port="5001" protocol="HTTP/1.1"
>               connectionTimeout="20000" redirectPort="8443" />
> 
>    <Connector port="4006" protocol="AJP/1.3" redirectPort="8443" />
> 
> So that tomcat only listens on the AJP port? Thanks.

Yes, just comment it out and restart.

p



> Best Regards,
> Jacob
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 


Tomcat Security - Disable the http connector

Posted by Jacob Rhoden <ja...@rhoden.id.au>.
Hi,

If I only allow connections to tomcat through apache (mod_jk), is it ok 
then to turn off the the  http connector, ie (for example in tomcat 6)

    <Connector port="5001" protocol="HTTP/1.1"
               connectionTimeout="20000" redirectPort="8443" />

    <Connector port="4006" protocol="AJP/1.3" redirectPort="8443" />

So that tomcat only listens on the AJP port? Thanks.

Best Regards,
Jacob

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat session varibale

Posted by Rashmi Rubdi <ra...@gmail.com>.
On 6/2/07, ibozo <ib...@ku.edu.tr> wrote:
>
> Thanks again..
> Here is my first code that takes two varibles from client to log in, as
> email adress and password. And puts the email adress into a session variable
> as:

With reference to the code in the previous post, it could be made a
lot simpler and easier if you follow the MVC design pattern.

Once you make it simpler you can easily see how to get the session in
a servlet and how to set and get values to it.

1) Write the HTML in a JSP instead of a Servlet

2) Use the Servlet as a medium between the front end (JSP) and the
back end (Java classes and JDBC)

3) Define the Servlet mapping in web.xml

4) Submit the form from the JSP to the Servlet (URL pattern from web.xml)

Take a look at this clickable diagram.

http://java.sun.com/blueprints/corej2eepatterns/Patterns/index.html

-Rashmi

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat session varibale

Posted by ibozo <ib...@ku.edu.tr>.
Thanks again..
Here is my first code that takes two varibles from client to log in, as
email adress and password. And puts the email adress into a session variable
as:

import javax.servlet.*;
import javax.servlet.http.*;

import java.io.*;
import java.sql.*;

public class sorguservlet extends HttpServlet {
	private static final String CONTENT_TYPE = "text/html";
	PreparedStatement pstmtCheckPassword;
	PreparedStatement pstmtGetName;
	
	public void init() throws ServletException {
		try {
			initializeJdbc();
		}
		catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	
	/**Initialize database connection*/
	private void initializeJdbc() {
		try {
			// Declare driver and connection string
//			String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
//			String connectionString = "jdbc:odbc:exampleMDBDataSource";
			// For Oracle
			String driver = "com.mysql.jdbc.Driver";
			String connectionString =
				"jdbc:mysql://localhost:3306/test?user=root&password=galatasaray";
			
			// Load the Oracle JDBC Thin driver
			Class.forName(driver);
			
			// Connect to the sample database
			Connection conn = DriverManager.getConnection
			(connectionString);
			
			// Create prepared statements
			pstmtCheckPassword = conn.prepareStatement("select count(*) from User
where EmailAdress = ? and Password = ?");
			pstmtGetName = conn.prepareStatement("select Datapath, Name, Date from
User where EmailAdress = ?");
		}
		catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	
	/**Process the HTTP Post request*/
	public void doPost(HttpServletRequest request,
			HttpServletResponse response)
	throws ServletException, IOException {
		// Write HTML back to a browser
		response.setContentType(CONTENT_TYPE);
		
		// Obtain a print stream for sending HMTL to the browser
		PrintWriter out = response.getWriter();
		
		// Obtain username and password
		String EmailAdress = request.getParameter("EmailAdress").trim();
		HttpSession session=request.getSession(true);
		session.setAttribute("EmailAdress", EmailAdress); 
		String Password = request.getParameter("Password").trim();
		
		// Check password
		try {
			pstmtCheckPassword.setString(1, EmailAdress.trim());
			pstmtCheckPassword.setString(2, Password.trim());
			ResultSet resultSet = pstmtCheckPassword.executeQuery();
			resultSet.next();
			if (resultSet.getInt(1) == 1 ) {
				
				pstmtGetName.setString(1, EmailAdress.trim());
				ResultSet resultSet2 = pstmtGetName.executeQuery();
				resultSet2.next();
				String Datapath= resultSet2.getString(1);
				String Name = new String (resultSet2.getString(2));
				String Date = new String (resultSet2.getString(3));
				out.println("<html>");
				out.println("<head><title> Welcome " + Name + "sikeyim" + "
</title></head>");
				out.println("<body>");
				out.println("<h1> Welcome " + Name + "</h1>");
		//		out.println("  http://172.18.4.138:8080/BigBrother" 
http://172.18.4.138:8080/BigBrother" <h1>" + Date + " </h1>  " );
				out.println("  http://172.18.4.138:8080/BigBrother/image.java"  
http://172.18.4.138:8080/BigBrother/image.java" <h1>" + Date + " </h1>  " );
				out.println("<br><br><br>
http://172.18.4.138:8080/BigBrother/Pictures/0.jpg ");
				out.println("</form>");
				out.println("</body>");
				out.println("</html>");
				
			} 	
			
			else{   	
				
				out.println("Your password or Email is incorrect. Please try again");
				
			}
		}
		catch (Exception ex) {
			ex.printStackTrace();
			return;
		}
	}
}

 
And here is my second code that takes the session variable and uses it to
search for the datapaths in database according to the given email adress by
the session variable as:



import javax.servlet.*;
import javax.servlet.http.*;

import java.io.*;
import java.sql.*;
public class image extends HttpServlet{
	PreparedStatement pstmtgetpic;
	
	public void init() throws ServletException {
		try {
			initializeJdbc();
		}
		catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	private void initializeJdbc() {
		try {
			// Declare driver and connection string
//			String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
//			String connectionString = "jdbc:odbc:exampleMDBDataSource";
			// For Oracle
			String driver = "com.mysql.jdbc.Driver";
			String connectionString =
				"jdbc:mysql://localhost:3306/test?user=root&password=galatasaray";
			
			// Load the Oracle JDBC Thin driver
			Class.forName(driver);
			
			// Connect to the sample database
			Connection conn = DriverManager.getConnection
			(connectionString);
			
			// Create prepared statements
			pstmtgetpic = conn.prepareStatement("select Datapath, Name, Date from
User where EmailAdress = ?");
		}
		catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	public void doGet(HttpServletRequest request,
			HttpServletResponse response)
	throws ServletException, IOException {
		// Write HTML back to a browser
		response.setContentType("text/html");
		
		// Obtain a print stream for sending HMTL to the browser
		PrintWriter out = response.getWriter();
		
		// Obtain username and password
		HttpSession session=request.getSession(false); 
		String EmailAdress= (String) session.getAttribute("EmailAdress"); 
		
		// Check password
		try {
			pstmtgetpic.setString(1, EmailAdress); 
			ResultSet resultSet2 = pstmtgetpic.executeQuery();
			resultSet2.next();
			String Datapath= new String( resultSet2.getString(1));
			String Name = new String (resultSet2.getString(2));
			
			out.println("<html>");
			out.println("<head><title> Welcome " + Name + "</title> ");
			out.println("  <meta http-equiv=Refresh content=5>");
			out.println("<body>");
			out.println("<h1> Welcome " + Name + "</h1>");
			out.println(" http://172.18.4.138:8080/BigBrother"+ ");
			
			out.println("</body>");
			out.println("</html>");
		}
		
		
		
		
		catch (Exception ex) {
			ex.printStackTrace();
			return;
		}
	}
}


if you can help me, I will get really appreciate.. 
Best,
ilker


Pid-2 wrote:
> 
> ibozo wrote:
>> Thank you for your help. I used the same codes as you told, however it
>> doesn't help me. Can there be a problem about Tomcat or with the "dopost"
>> and "doget" methods that I use. I took the session variables inside a
>> "dopost" program and I used those session variables in a "doget" program.
>> Waiting for your help..
>> Best,
>> ilker 
> 
> Post your code so we can see what you're doing in each.
> 
> p
> 
> 
>> Rashmi Rubdi-2 wrote:
>>> On 6/1/07, ibozo <ib...@ku.edu.tr> wrote:
>>>> Hello all,
>>>>    I have created a file of servlet pages that publish those pages in
>>>> Tomcat
>>>> 6. I have a log in page, programmed by servlet and also another page
>>>> that
>>>> activates the application acording to the given parameters by serching
>>>> webserver. I should use the taken variable on the log in page in
>>>> another
>>>> servlet page. I tried to create a session variable and use it inside
>>>> the
>>>> other web servlet.
>>> I guess you are trying to access a value stored in the HttpSession in
>>> one Servlet inside another Servlet.
>>>
>>> This is very simple ...
>>>
>>> in the first Servlet , you are doing
>>>
>>> HttpSession session = request.getSession();
>>> session.setAttribute("MyAttribute", "MyValue");
>>>
>>> in the  second Servlet you would write
>>>
>>>
>>> HttpSession session = request.getSession();
>>> session.getAttribute("MyAttribute");
>>>
>>>> However I am unable to suceed... Can you help me as soon
>>> It works because the HttpRequest object is available to all Servlet's
>>> inside their doPost and doGet methods.
>>>
>>>> as possible..
>>>> Best,
>>>> ilker
>>> I recommend you read about Servlets, it's all covered in the basics.
>>>
>>> -Rashmi
>>>
>>> ---------------------------------------------------------------------
>>> To start a new topic, e-mail: users@tomcat.apache.org
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>>
>>>
>> 
> 
> 
>  
> 

-- 
View this message in context: http://www.nabble.com/Tomcat-session-varibale-tf3854667.html#a10926044
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat session varibale

Posted by Pid <p...@pidster.com>.
ibozo wrote:
> Thank you for your help. I used the same codes as you told, however it
> doesn't help me. Can there be a problem about Tomcat or with the "dopost"
> and "doget" methods that I use. I took the session variables inside a
> "dopost" program and I used those session variables in a "doget" program.
> Waiting for your help..
> Best,
> ilker 

Post your code so we can see what you're doing in each.

p


> Rashmi Rubdi-2 wrote:
>> On 6/1/07, ibozo <ib...@ku.edu.tr> wrote:
>>> Hello all,
>>>    I have created a file of servlet pages that publish those pages in
>>> Tomcat
>>> 6. I have a log in page, programmed by servlet and also another page that
>>> activates the application acording to the given parameters by serching
>>> webserver. I should use the taken variable on the log in page in another
>>> servlet page. I tried to create a session variable and use it inside the
>>> other web servlet.
>> I guess you are trying to access a value stored in the HttpSession in
>> one Servlet inside another Servlet.
>>
>> This is very simple ...
>>
>> in the first Servlet , you are doing
>>
>> HttpSession session = request.getSession();
>> session.setAttribute("MyAttribute", "MyValue");
>>
>> in the  second Servlet you would write
>>
>>
>> HttpSession session = request.getSession();
>> session.getAttribute("MyAttribute");
>>
>>> However I am unable to suceed... Can you help me as soon
>> It works because the HttpRequest object is available to all Servlet's
>> inside their doPost and doGet methods.
>>
>>> as possible..
>>> Best,
>>> ilker
>> I recommend you read about Servlets, it's all covered in the basics.
>>
>> -Rashmi
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>>
> 


Re: Tomcat session varibale

Posted by ibozo <ib...@ku.edu.tr>.
Thank you for your help. I used the same codes as you told, however it
doesn't help me. Can there be a problem about Tomcat or with the "dopost"
and "doget" methods that I use. I took the session variables inside a
"dopost" program and I used those session variables in a "doget" program.
Waiting for your help..
Best,
ilker 

Rashmi Rubdi-2 wrote:
> 
> On 6/1/07, ibozo <ib...@ku.edu.tr> wrote:
>>
>> Hello all,
>>    I have created a file of servlet pages that publish those pages in
>> Tomcat
>> 6. I have a log in page, programmed by servlet and also another page that
>> activates the application acording to the given parameters by serching
>> webserver. I should use the taken variable on the log in page in another
>> servlet page. I tried to create a session variable and use it inside the
>> other web servlet.
> 
> I guess you are trying to access a value stored in the HttpSession in
> one Servlet inside another Servlet.
> 
> This is very simple ...
> 
> in the first Servlet , you are doing
> 
> HttpSession session = request.getSession();
> session.setAttribute("MyAttribute", "MyValue");
> 
> in the  second Servlet you would write
> 
> 
> HttpSession session = request.getSession();
> session.getAttribute("MyAttribute");
> 
>> However I am unable to suceed... Can you help me as soon
> 
> It works because the HttpRequest object is available to all Servlet's
> inside their doPost and doGet methods.
> 
>> as possible..
>> Best,
>> ilker
> 
> I recommend you read about Servlets, it's all covered in the basics.
> 
> -Rashmi
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Tomcat-session-varibale-tf3854667.html#a10924824
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat session varibale

Posted by Rashmi Rubdi <ra...@gmail.com>.
On 6/1/07, ibozo <ib...@ku.edu.tr> wrote:
>
> Hello all,
>    I have created a file of servlet pages that publish those pages in Tomcat
> 6. I have a log in page, programmed by servlet and also another page that
> activates the application acording to the given parameters by serching
> webserver. I should use the taken variable on the log in page in another
> servlet page. I tried to create a session variable and use it inside the
> other web servlet.

I guess you are trying to access a value stored in the HttpSession in
one Servlet inside another Servlet.

This is very simple ...

in the first Servlet , you are doing

HttpSession session = request.getSession();
session.setAttribute("MyAttribute", "MyValue");

in the  second Servlet you would write


HttpSession session = request.getSession();
session.getAttribute("MyAttribute");

> However I am unable to suceed... Can you help me as soon

It works because the HttpRequest object is available to all Servlet's
inside their doPost and doGet methods.

> as possible..
> Best,
> ilker

I recommend you read about Servlets, it's all covered in the basics.

-Rashmi

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org