simple jsp problem.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting simple jsp problem.
# 8  
Old 09-03-2010
Quote:
Originally Posted by kevintse
I don't see anything wrong in your code, it should have worked.

Well, what errors did you get when it didn't redirect you to "cgipage.jsp"? did all your code compile fine?

I guess it might be that you were redirected to the expected page, but there're some errors in your "cgipage.jsp" page. I don't know...

You may check log messages under $TOMCAT_HOME/logs, and make sure your code compile.
I dont get any error message but even if i put the right credentials to login,the same page comes again (i.e login.jsp).

following log get generated under $TOMCAT_HOME/logs/catalina.out

Code:
# tail -f catalina.out
INFO: JK: ajp13 listening on /0.0.0.0:8009
Sep 1, 2010 10:51:30 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/259  config=null
Sep 1, 2010 10:51:30 AM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Sep 1, 2010 10:51:30 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 25153 ms
null
oracle.jdbc.driver.OracleDriver
oracle.jdbc.driver.OracleDriver


oracle.jdbc.driver.OracleDriver

everytime i refresh the page an entry "oracle.jdbc.driver.OracleDriver" is written to the log.
However if i use the old path i.e.The UNIX and Linux Forums - Learn UNIX and Linux from Experts
things works fine and i get redirected to cgipage.jsp.There fore i think there should not be a problem in cgipage.jsp page.Anyway i m posting the code for cgipage.jsp as well.
Code:
<%@ page import="java.lang.*" language="java"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>

<%
  Object user = session.getAttribute("user");
  Object fullname =session.getAttribute("fullname");
  Object role=session.getAttribute("role");
  String Str_startstop="no";
  if (null == user) {
    response.sendRedirect("login.jsp");
  }
  try
{
//Triming Username and Password
         Object  usernameobj   = session.getAttribute("user");

         String username=usernameobj.toString();

         Connection conn=null;
         Statement stmt=null;
         ResultSet rs=null;
         String startstoprole =  null;
         Class.forName ("oracle.jdbc.driver.OracleDriver");
         conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "lightweight", "oracle");
                            // @machineName:port:SID,   userid,  password
        String sql = "select * from LIGHT_ROLE where USERNAME='"+username+"'";
        stmt = conn.createStatement();
        rs = stmt.executeQuery(sql);
        while( rs.next() )
        {
         //Getting Username,Password,roll,Fullname from Database.
         startstoprole=rs.getString("PERMISSION");
        }

        if(startstoprole.equals("yes"))
        {
        session.setAttribute("startstoprole","yes");
        }
        else
        {
        session.setAttribute("startstoprole","no");
        }
Object startstoproleobj =session.getAttribute("startstoprole");
Str_startstop=startstoproleobj.toString();
}
catch(Exception e)
{
out.println(e.getMessage());
}


%>

<html>
<head>
<title>Light Weight Manager</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>

<b>Hi,</b> <%=fullname%>

<!-- Serch Virtual Guest Form -->
<FORM NAME="SEARCHVIRTUALGUEST" METHOD="GET" ACTION="http://localhost:8080/VM_Finder_V3.cgi">
<hr size=2 noshade>
  Enter VM Host Name(ALL IN CAP):
<%
try
{
if (role.equals("user"))
{
        Connection conn=null;
        Statement stmt=null;
        ResultSet rs=null;
        Class.forName ("oracle.jdbc.driver.OracleDriver");
        conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "lightweight", "oracle");
                            // @machineName:port:SID,   userid,  password

        String sql = "select * from LIGHT_INVENTORY where USERNAME='"+user+"'";
        stmt = conn.createStatement();
        rs = stmt.executeQuery(sql);%>
        <select name="mc" size="1"><%
        while( rs.next() )
        {
 {
        String host=rs.getString(2);%>
        <option value="<%=host%>"><%=host%></option>

       <% }%>

        </select>
<INPUT TYPE="submit">

</FORM>
<%
rs.close();
stmt.close();
conn.close();
}
else
{
%>
<INPUT TYPE="text" NAME="mc">
<INPUT TYPE="submit">
</FORM>
<!-- End of Serch Virtual Guest Form -->

<%}
}
catch(Exception e)
{
}
%>


<%
if(Str_startstop.equals("yes"))
{
%>
<FORM name="form4" METHOD="GET" ACTION="http://localhost:8080/vm_start_V1.cgi">
Please Type VM Host Name(ALL IN CAP): <INPUT TYPE="text" NAME="machine">
<input type="submit" name="Submit" value="Power On"> </FORM>

<FORM name="form3" METHOD="GET" ACTION="http://localhost:8080/VM_Stop_V2.cgi">
Please Type VM Host Name(ALL IN CAP): <INPUT TYPE="text" NAME="machine">
<input type="submit" name="Submit" value="Power Off">
</FORM>
<%
}
%>

<form name=logout action=logout.jsp method=post>
<input type=submit value="LogOut">
</form>

</body>
</html>

# 9  
Old 09-03-2010
At the very first part of your "cgipage.jsp" page, I see this code:
Code:
Object user = session.getAttribute("user");
....
if (null == user) {
    response.sendRedirect("login.jsp");
  }

I guess this is the problem, "user" may not be set in session for some reasons and it is null, so you are redirected back to "login.jsp" as the code does.

I hope you would have solved your problem before seeing this reply, it shouldn't difficult.
# 10  
Old 09-03-2010
Quote:
Originally Posted by kevintse
At the very first part of your "cgipage.jsp" page, I see this code:
Code:
Object user = session.getAttribute("user");
....
if (null == user) {
    response.sendRedirect("login.jsp");
  }

I guess this is the problem, "user" may not be set in session for some reasons and it is null, so you are redirected back to "login.jsp" as the code does.

I hope you would have solved your problem before seeing this reply, it shouldn't difficult.
As i mentioned in my earlier post .The same page when loaded with an old URL things works pretty well.But after the configuration changes to load it from The UNIX and Linux Forums - Learn UNIX and Linux from Experts ,Problem seems to occure.

In both the cases cgipage.jsp is the same .

As per login page after a successful login i m setting a session variable .
Code:
if(trim_Username.equals(id) && trim_Password.equals(pin))
        {
 out.println("login successful");
        session.setAttribute("user",trim_Username);
        session.setAttribute("fullname",fullname);
        session.setAttribute("role",role);
        response.sendRedirect("cgipage.jsp");
        }


Last edited by pinga123; 09-03-2010 at 08:52 AM..
# 11  
Old 09-03-2010
OK, seems weird...
So you have to do some tests and see whether you were ever redirected to "cgipage.jsp" and redirected back to "login.jsp" for some reasons.
Add the following to your "cgipage.jsp" page, and see whether there are something printed to the console or logged in "$TOMCAT_HOME/logs/catalina.out", or there are something but it is a "null"...you know what's the problem:
Code:
<% System.out.println(session.getAttribute("user")); %>

You may also want to add some "System.out.println()"s to "login.jsp" and see how many times it has been accessed after you press the "login" button.

This is the help I can offer for the moment.

PS: Logging message to the jvm console using System.out.println() is always discouraged in production code, but it can be useful when troubleshooting.
# 12  
Old 09-06-2010
Quote:
Originally Posted by kevintse
OK, seems weird...
So you have to do some tests and see whether you were ever redirected to "cgipage.jsp" and redirected back to "login.jsp" for some reasons.
Add the following to your "cgipage.jsp" page, and see whether there are something printed to the console or logged in "$TOMCAT_HOME/logs/catalina.out", or there are something but it is a "null"...you know what's the problem:
Code:
<% System.out.println(session.getAttribute("user")); %>

You may also want to add some "System.out.println()"s to "login.jsp" and see how many times it has been accessed after you press the "login" button.

This is the help I can offer for the moment.

PS: Logging message to the jvm console using System.out.println() is always discouraged in production code, but it can be useful when troubleshooting.
I dont get any error message but even if i put the right credentials to login,the same page comes again (i.e login.jsp).

following log get generated under $TOMCAT_HOME/logs/catalina.out


Code:
Code:
# tail -f catalina.out
INFO: JK: ajp13 listening on /0.0.0.0:8009
Sep 1, 2010 10:51:30 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/259  config=null
Sep 1, 2010 10:51:30 AM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Sep 1, 2010 10:51:30 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 25153 ms
null
oracle.jdbc.driver.OracleDriver
oracle.jdbc.driver.OracleDriver

everytime i refresh the page an entry "oracle.jdbc.driver.OracleDriver" is written to the log.

---------- Post updated at 10:37 PM ---------- Previous update was at 10:37 PM ----------

Quote:
Originally Posted by pinga123
I dont get any error message but even if i put the right credentials to login,the same page comes again (i.e login.jsp).

following log get generated under $TOMCAT_HOME/logs/catalina.out


Code:
Code:
# tail -f catalina.out
INFO: JK: ajp13 listening on /0.0.0.0:8009
Sep 1, 2010 10:51:30 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/259  config=null
Sep 1, 2010 10:51:30 AM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Sep 1, 2010 10:51:30 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 25153 ms
null
oracle.jdbc.driver.OracleDriver
oracle.jdbc.driver.OracleDriver

everytime i refresh the page an entry "oracle.jdbc.driver.OracleDriver" is written to the log.
Do you think it has something to do with database?
# 13  
Old 09-06-2010
Quote:
Originally Posted by pinga123
Do you think it has something to do with database?
I don't think so, try logging and finding the cause in the log messages.

In your catalina.out, i spot a "null", what was that?
Code:
...
INFO: Server startup in 25153 ms
null
oracle.jdbc.driver.OracleDriver
...

# 14  
Old 09-06-2010
This happened when i supplied incorrect login name.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

simple wc problem

Hi there, Im sure there is a simple explanation for this but I have a file like this with no balnk lines peter paul john I run the command # var=`grep paul file.txt` # echo $var paul # echo $var | wc -l 1 but when I grep for a value that isnt in the file, i still... (4 Replies)
Discussion started by: rethink
4 Replies

2. Shell Programming and Scripting

Please help me with a simple problem

Hi, I have a very simple script like below: for n in 10 20 30 do for a in 30 40 50 60 70 80 do for r in 2 3 4 5 6 7 do m=$((r*a)) count=1 while do echo "a = " $a ", m = " $m ", n = " $n ... (2 Replies)
Discussion started by: Dark2Bright
2 Replies

3. Programming

Problem in reflecting changes made on a JSP File

I make some changes in a JSP file but the changes do not reflect on tomcat server. In my server.xml 'reloadable' paramtere is set to true. I even treid restarting the server. The changes still not reflect. The changes do reflect in a day or two. am not sure why this is happening. Shall... (3 Replies)
Discussion started by: Shikha Agrawal
3 Replies

4. Programming

Please I need your help about jsp and java

Hello.. is there any way to send a file or a string from jsp website to java program which all I will develope i remember that i can make socket connection between jsp and java but:confused::confused: I dont now how if there any website or booke explain that or if there another way ... (2 Replies)
Discussion started by: vip_a1
2 Replies

5. Shell Programming and Scripting

i want to edit my jsp page using script

hi I have one jsp file. i want to edit this jsp page using script. This jsp page contains ("insert into employee values('raja', 32, ' ');) i want to add empty column at the end of the line. i.e is that line should be (insert into employee values('raja', 32, ' ', ' ');) (2 Replies)
Discussion started by: nsundaram_cse
2 Replies

6. Shell Programming and Scripting

calling unix script from JSP???

Hi all, i have requirement where i need to call a unix script from a JSP code. my script should list all the csv files from a directory and then should upload the file names to an oracle table (using sqlloader). i tried using getRuntime function in JAVA to call my script and was successfully... (1 Reply)
Discussion started by: Bhups
1 Replies

7. Shell Programming and Scripting

Code conversion from JSP to PYTHON

Guys I need to convert a code from JSP (Java Tags are also there inside JSP) to PYTHON. I have OK kind of knowledge in PYTHON, but dont have a muck knowledge in JAVA/JSP. Any idea how to approach? Thanks in advance to all C Saha (1 Reply)
Discussion started by: csaha
1 Replies

8. UNIX for Dummies Questions & Answers

JSP on an HP UX-11

We have an HP UX-11 server running Unix and we wish to run Java Server Pages on this system. Can anyone see a reason why these pages will not work under this environment. Thanks for you help. Matthew (2 Replies)
Discussion started by: MLarra51
2 Replies

9. Shell Programming and Scripting

user creation using shell script for JSP

hello friends, I have problem. We want to create user from jsp(browser based) on our linux server. How we can do that ? or How do we create a user with shell programming by taking arguments and checking with the existing users and if the user exist it should display the message the user exists... (1 Reply)
Discussion started by: jarkvarma
1 Replies
Login or Register to Ask a Question