• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help with jsp page so that it calls a good working bean

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want a jsp page to login into a javabean.
The class below Ftplogin.java uses an FtpBean to login.
In other parts of the Web the ftpbean will be used to do ftp operations like view files, close ftp, make files etc.
The ftpbean is faily substantial class.
How can I use the ftplogin.jsp below to login into a ftp client?
class FtpLogin implements FtpObserver
{
FtpBean ftp;
long num_of_bytes = 0;
public FtpLogin()
{
// Create a new FtpBean object.
ftp = new FtpBean();
}
// Connect to a ftp server.
public void connect()
{
try
{
ftp.ftpConnect("ftp.cs.cuhk.edu.hk", "anonymous", "citidancer@hongkong.com");
} catch(Exception e)
{
System.out.println(e);
}
}
}

<!-- below is a jsp called ftplogin.jsp -->
<html>
<head>
<title> FTP Login </title>
</head>
<body>

<h1> Welcome to the FTP Login. </h1>

Enter name of server:
<input type="text" name="serverName"><br>
Enter user name?
<input type="text" name="userName"><br>
Enter password
<input type="text" name="passwordName"><br>
<input type="submit" name="Submit info">
</body>
</html>
Please help
 
Ranch Hand
Posts: 395
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can do it in two ways.
1. use the <jsp:useBean> taga nd instantiate the bean for page scope and call the method in the ftpbean class to validate the user.
2. Pass the request back to server, to a servlet in which the bean is instantiated and validated.
You can have this FTPBean class already instantiated for either application or session scope. This will help you to use the bean in all the pages where you need to validate the user.

Hope this helps.
Cheers.
 
northfield Sid
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> You can have this FTPBean class already instantiated for either application or session scope. This will help you to use the bean in all the pages where you need to validate the user.
The ftpBean will be used throughtout the web so thus wouldn't it be better to have session or application scope rather than page scope?
I have a book that gives example of page scope access to a simplebean. What would it mean to use page scope?
 
northfield Sid
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a JSP page called ftplogin.jsp
I want the jsp page to call a ftpbean using session scope.
It will pass server, username and login into the ftpbean.
It will then set the directory and finaly retrieve a a document from it.
The ftpbean works but my jsp page doesn't. Please help with compilation problem???
Please also tell me if the syntax of accessing the bean is correct?
<!-- ftplogin.jsp -->
<html>
<head>
<title> FTP Login </title>
</head>
<body>
<%@ page import= "ftp.* " %>
<jsp:useBean class="ftp.FtpBean" id="ftpbean" scope="session" />
<%
try
{
String servername = request.getParameter("serverName");
String username = request.getParameter("username");
String password = request.getParameter("password");
ftpbean.ftpConnect(servername, username, password);
}
catch(Exception e)
{
%>
Sorry but your must have entered an incorrect login ingotmation.
You are not allowed to login.
Please leave the ftp portal.

<%
}
%>

<h1> Welcome to the FTP Login. </h1>
<FORM ACTION="ftplogin.jsp" METHOD=post>
Please login
Enter name of server:
<input type="text" name="servername"><br>
Enter user name?
<input type="text" name="username"><br>
Enter password
<input type="text" name="password"><br>
<input type="submit" name="Submit info">
</FROM>
<%=
try
{
// set the directory
ftpbean.setDirectory("/home/eland/u6/k3074/w0109699/simple-bean");

}
catch(Exception e)
{
System.out.println(e);
}
%>
<%=
try
{
// Get the binary file '???' and save it to hard disk
// the name will be 'local_file_name' .

ftpbean.getBinaryFile("accessbean.jsp", "local_file_name", this);
}
catch(Exception e)
{
System.out.println(e);
}
%>
<%=
try
{
ftpbean.close();
}
catch(Exception e)
{
System.out.println(e);
}
%>
</body>
</html>
Location: /myJSPs/jsp/grid-portal-project/ftplogin.jsp
Internal Servlet Error:
org.apache.jasper.JasperException: Unable to compile Note: sun.tools.javac.Main has been deprecated.
C:\tomcat\jakarta-tomcat-3.3.1\work\DEFAULT\myJSPs\jsp\grid_0002dportal_0002dproject\ftplogin_1.java:110: Missing term.
out.print(
^
C:\tomcat\jakarta-tomcat-3.3.1\work\DEFAULT\myJSPs\jsp\grid_0002dportal_0002dproject\ftplogin_1.java:110: ')' expected.
out.print(
^
C:\tomcat\jakarta-tomcat-3.3.1\work\DEFAULT\myJSPs\jsp\grid_0002dportal_0002dproject\ftplogin_1.java:120: Missing term.
}
^
C:\tomcat\jakarta-tomcat-3.3.1\work\DEFAULT\myJSPs\jsp\grid_0002dportal_0002dproject\ftplogin_1.java:120: ';' expected.
}
^
C:\tomcat\jakarta-tomcat-3.3.1\work\DEFAULT\myJSPs\jsp\grid_0002dportal_0002dproject\ftplogin_1.java:121: Invalid expression statement.
);
^
5 errors, 1 warning
at org.apache.tomcat.facade.JasperLiaison.javac(JspInterceptor.java:898)
at org.apache.tomcat.facade.JasperLiaison.processJspFile(JspInterceptor.java:733)
at org.apache.tomcat.facade.JspInterceptor.requestMap(JspInterceptor.java:506)
at org.apache.tomcat.core.ContextManager.processRequest(ContextManager.java:968)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:875)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:536)
 
northfield Sid
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry the code is not very readable:
I have a JSP page called ftplogin.jsp
I want the jsp page to call a ftpbean using session scope.
It will pass server, username and login into the ftpbean.
It will then set the directory and finaly retrieve a a document from it.
The ftpbean works but my jsp page doesn't. Please help with compilation problem???
Please also tell me if the syntax of accessing the bean is correct?

Here is the error:
Location: /myJSPs/jsp/grid-portal-project/ftplogin.jsp
Internal Servlet Error:
org.apache.jasper.JasperException: Unable to compile Note: sun.tools.javac.Main has been deprecated.
C:\tomcat\jakarta-tomcat-3.3.1\work\DEFAULT\myJSPs\jsp\grid_0002dportal_0002dproject\ftplogin_1.java:110: Missing term.
out.print(
^
C:\tomcat\jakarta-tomcat-3.3.1\work\DEFAULT\myJSPs\jsp\grid_0002dportal_0002dproject\ftplogin_1.java:110: ')' expected.
out.print(
^
C:\tomcat\jakarta-tomcat-3.3.1\work\DEFAULT\myJSPs\jsp\grid_0002dportal_0002dproject\ftplogin_1.java:120: Missing term.
}
^
C:\tomcat\jakarta-tomcat-3.3.1\work\DEFAULT\myJSPs\jsp\grid_0002dportal_0002dproject\ftplogin_1.java:120: ';' expected.
}
^
C:\tomcat\jakarta-tomcat-3.3.1\work\DEFAULT\myJSPs\jsp\grid_0002dportal_0002dproject\ftplogin_1.java:121: Invalid expression statement.
);
^
5 errors, 1 warning
at org.apache.tomcat.facade.JasperLiaison.javac(JspInterceptor.java:898)
at org.apache.tomcat.facade.JasperLiaison.processJspFile(JspInterceptor.java:733)
at org.apache.tomcat.facade.JspInterceptor.requestMap(JspInterceptor.java:506)
at org.apache.tomcat.core.ContextManager.processRequest(ContextManager.java:968)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:875)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:536)
 
northfield Sid
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have simplified the code by mainly taking out the try and catch.
It now gives me one error but I am no closer to make it compile with no errors.
I eventually want to put back the try-catch statement to handle errors.
Please help

Location: /myJSPs/jsp/grid-portal-project2/ftplogin.jsp
Internal Servlet Error:
org.apache.jasper.JasperException: Unable to compile Note: sun.tools.javac.Main has been deprecated.
C:\tomcat\jakarta-tomcat-3.3.1\work\DEFAULT\myJSPs\jsp\grid_0002dportal_0002dproject2\ftplogin_1.java:99: ')' expected.
ftp.setDirectory("/home/eland/u6/k3074/w0109699/simple-bean");
^
1 error, 1 warning
at org.apache.tomcat.facade.JasperLiaison.javac(JspInterceptor.java:898)
at org.apache.tomcat.facade.JasperLiaison.processJspFile(JspInterceptor.java:733)
at org.apache.tomcat.facade.JspInterceptor.requestMap(JspInterceptor.java:506)
at org.apache.tomcat.core.ContextManager.processRequest(ContextManager.java:968)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:875)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:536)
 
northfield Sid
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please note I have solved the compilation problem.
But now getting runtime error I think. Here is the error:
Error: 500
Location: /myJSPs/jsp/grid-portal-project2/ftplogin.jsp
Internal Servlet Error:
javax.servlet.ServletException
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:460)
at jsp.grid_0002dportal_0002dproject2.ftplogin_1._jspService(ftplogin_1.java:128)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:536)
Root cause:
java.lang.NullPointerException
at java.net.Socket.(Socket.java:282)
at java.net.Socket.(Socket.java:118)
at ftp.FtpBean.ftpConnect(FtpBean.java:323)
at ftp.FtpBean.ftpConnect(FtpBean.java:293)
at jsp.grid_0002dportal_0002dproject2.ftplogin_1._jspService(ftplogin_1.java:91)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:536)
Here is my directory structure for ".jsp" and ".html" pages:
C:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\jsp\grid-portal-project2
Here is my directory structure for java classes,
C:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\WEB-INF\classes
ftp
ftp\FtpBean.java
ftp\FtpBean.class

Here is the modified source code:
 
northfield Sid
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please help.
I still cannot get the program to run:
Please help as I still have not been able to solve the latest error:
Internal Servlet Error:
javax.servlet.ServletException
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:460)
at jsp.grid_0002dportal_0002dproject2.ftplogin_1._jspService(ftplogin_1.java:128)
...
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You seem to be confused about the flow of the code and what happens when. Any scriptlet code you place in a JSP happens before the HTML is ever displayed on the client. That means that when your scriptlet code runs in the JSP file you posted, the form has not yet been presented to the client. The NullPointerException you're seeing is most likely the result of that.
You want to split this up into two parts. The first, which may as well just be a plain HTML file, is the form that asks for this information. The second piece is a JSP (or better yet, a servlet), that calls request.getParameter(...) and then calls the methods of your FTP-related object.
Hope that helps,
Chris
 
northfield Sid
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chris Smith
Thanks that was helpful.
Was getting a little confused
 
reply
    Bookmark Topic Watch Topic
  • New Topic