Janet Yap

Greenhorn
+ Follow
since Mar 13, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Janet Yap

Hi Mohd Afroz Ahmed,
I have changed the codes as what you have suggested. The jsp can display the bean property now.
Thanks.
20 years ago
Thanks for your opinion. I agree with both of you. What is stated in the book may not be practical and may not being practised in the real world. All the examples used in the reference are of a simple one. Thus, it is possible to put all classes in an analysis diagram.
May I know what is the practice in the real project world? Are there normally have more than one analysis class diagram? Can I create an analysis class diagram for each use case instead?Can I just include persistent entity objects in an analysis class diagram?
Hi,
I am developing a web-based information system for my project. This system will be developed using based on Model-View-Controller model. I have the following problems in applying UML for the project:
1.Do we include boundary objects and controller object in an analysis class diagram?
2.According to my project manager, we can have ONLY ONE analysis class diagram for a project. I wonder how all the classes can be fit into a diagram if we have a large number of classes.
3.System sequence diagram is used to document all the external events to the System. Is this mean that an operation (or system event) need to be created for every user click at a HTML page. If a user need to perform 10 clicks on html pages to compete a use case, is that means there will be 10 system events in the system sequence diagram of the use case.
4.How many collaboration diagram will we have for a use case? Is it ONE for each use case or ONE for each system event of a use case? (i.e. if the use case has 5 system events/operation, then 5 collaboration diagrams need to be created?)
Please advise. Thanks.
[ March 15, 2004: Message edited by: Janet Yap ]
When i try the codes above, I get this error:
java.lang.IllegalArgumentException: Path ../jsp/transactionDisplay.jsp does not start with a "/" character
at org.apache.catalina.core.ApplicationContext.getRequestDispatcher(ApplicationContext.java:570)
at org.apache.catalina.core.ApplicationContextFacade.getRequestDispatcher(ApplicationContextFacade.java:174)
at TransactionHandler.doPost(TransactionHandler.java:21)
..................................
.........somemore error codes......
When I replace the relative url with absolute url, I still get the following error:
java.lang.IllegalArgumentException: Path http://localhost:8080/examples/jsp/transactionDisplay.jsp does not start with a "/" character
at org.apache.catalina.core.ApplicationContext.getRequestDispatcher(ApplicationContext.java:570)
at org.apache.catalina.core.ApplicationContextFacade.getRequestDispatcher(ApplicationContextFacade.java:174)
....................................
What will the correct codes look like?
20 years ago
thanks for your reply.
I am new in programming and I have never use RequestDispatcher method before. Can someone show me how this method can be used for this problem?
Is it correct if i replace the line in TransactionHandler.java:
res.sendRedirect("../jsp/transactionDisplay.jsp");
with these:
String url= "../jsp/transactionDisplay.jsp";
RequestDispatcher dis=getServletContext().getRequestDispatcher(url);
dis.forward(req,res);
20 years ago
can I have the particulars of the book, i.e. the isbn and author name.
20 years ago
Hi,
I am using a form to activate a servlet that will set the property of a bean and a JSP to retrieve the bean property. But, the Servlet fails to set the property of the bean.
The following are the codes written for the respective file:
Form:
*************************************************
<html><titile>Transaction Form</title>
<head><body>
<form action="http://localhost:8080/examples/servlet/TransactionHandler" method="post">
<input type="submit" value="click here to set the bean">
</form></body></head></html>
*****************************************************
TransactionHandler.java:
******************************************************
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import beans.TransactionBean;
public class TransactionHandler extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
TransactionBean tt= new TransactionBean();
tt.setGivenName("my given name");
tt.setFamilyName("my family name");
tt.setAddress("my address");
req.setAttribute("student", "tt");
res.sendRedirect("../jsp/transactionDisplay.jsp");
}
}
**************************************************************************
TransactionBean.java:
************************************************************
package beans;
public class TransactionBean
{
private String givenName;
private String familyName;
private String address;

public void setGivenName(String name)
{
givenName=name;
}
public void setFamilyName(String name)
{
familyName=name;
}
public void setAddress(String input)
{
address=input;
}

public String getGivenName()
{
return givenName;
}

public String getFamilyName()
{
return familyName;
}
public String getAddress()
{
return address;
}
}
********************************************************
transactionDisplay.jsp:
**********************************************************
<%@ page import="java.lang.*" %>
<html>
<head><title>Transaction Display Page</title>
</head>
<body>
<jsp:useBean id="student" class="beans.TransactionBean" scope="request" />
<%
String givenName=student.getGivenName();
String familyName=student.getFamilyName();
String address=student.getAddress();
%>

<p><b>Student Name:<%=givenName%> <%=familyName%></b></p>
<p><b>Address:<%=address%></b></p>
</body></html>
************************************************************************
This is the result i get:
Student Name:null null
Address:null
May I know what mistakes i have made?
20 years ago
thanks for yor reply
the problem is solved after i have placed the package under C:\Tomcat\webapps\WEB-INF\class directory
20 years ago
Thanks.
the servlet can recognise the package after i have reset the classpath.
20 years ago
Hi everyone,
I have create a java bean in a folder called mybeans located at:
C:\Tomcat\classes\mybeans
I can call this bean via jsp without any problem. These are the codes in the jsp file:
*****************************************************
<%@ page language="java" contentType="text/html" %>
<html><head><title>Using Simple Bean</title></head><body>
<%-- create an instance of the SimpleBean --%>
<jsp:useBean id="msg" class="mybeans.SimpleBean" />
<jsp:setProperty name="msg" property="message1" value="Saying Hello" />
<jsp:setProperty name="msg" property="message2" value="with a JavaBean" />
<b><font color="red"><jsp:getProperty name="msg" property="message1" /></font></b>
<i><font color="red"><jsp:getProperty name="msg" property="message2" /></font></i>
</body></html>
**************************************************************************

However, when i try to use this bean in a servlet, i have problem to compile the servlet. The following is the error i get when i compile it:
**********************************************
Message.java:4: package mybeans does not exist
import mybeans.SimpleBean;
^
Message.java:13: cannot resolve symbol
symbol : class SimpleBean
location: class Message
SimpleBean t= new SimpleBean();
^
Message.java:13: cannot resolve symbol
symbol : class SimpleBean
location: class Message
SimpleBean t= new SimpleBean();
^
Message.java:25: cannot resolve symbol
symbol : variable t
location: class Message
String a=t.getMessage1();
^
Message.java:26: cannot resolve symbol
symbol : variable t
location: class Message
String b=t.getMessage2();
^
5 errors
**************************************************
The codes in the java bean are as follows:
package mybeans;
public class SimpleBean
{
private String message1;
private String message2;

public void setMessage1(String input)
{
message1=input;
}
public String getMessage1()
{
return message1;
}
public void setMessage2(String input)
{
message2=input;
}
public String getMessage2()
{
return message2;
}
}
************************************************************
whereas, the java servlet has the following codes:
***********************************************************
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import mybeans.SimpleBean;
public class Message extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
SimpleBean t= new SimpleBean();
t.setMessage1("Hello,");
t.setMessage1("SP");

}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
PrintWriter out = res.getWriter();
String a=t.getMessage1();
String b=t.getMessage2();
out.println("<html>");
out.println("<body>");
out.print("+a+");
out.println("+b+");
out.println("</body>");
out.println("</html>");
}
}
**********************************************************
May I know how this problem can be solved?
20 years ago
Hi,
I wish to appy MVC model in developing a website. But, I am not sure in writing codes for the java bean and servlet.
I plan to use a java serlvet as a Controller to process the information submitted by a form.
A java bean will be used as a model to access the database via SQL to retrive and store the data that meet the criteria.
Based on the information submitted via a form, the servlet will set the property of the bean.
A jsp will get the data retrived from the database via java bean for display.
Can I have some examples of codes for java bean(the model) and java serlvet(the Controller) that can be used for the scenario as described above.
20 years ago
JSP
I have create a java bean named TransactionBean and save it under C:\Tomcat\webapps\examples\WEB-INF\classes\bean
The transaction codes are started as follows:
__________________________________________________
package beans;
public class TransactionBean
{
all the codes is writen here
}
_______________________________________________________________________
This java bean is used by a java servlet(TransactionHandler.java)that has the follwoing codes:
_______________________________________________________________________
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;
import beans.TransactionBean;

public class TransactionHandler extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
int studentId=Integer.parseInt(req.getParameter("studentId"));
............some other codes..........

TransactionBean trans= new TransactionBean();
trans.setStudentId(rst.getInt("student_id"));

}
___________________________________________________________________________
I have no problem in compiling the java beans.
However, when i compile the java servlet(TransactionHandler.java), I get these error message:
C:\Tomcat\webapps\examples\WEB-INF\classes>javac TransactionHandler.java
TransactionHandler.java:6: package beans does not exist
import beans.TransactionBean;
^
TransactionHandler.java:31: cannot resolve symbol
symbol : class TransactionBean
location: class TransactionHandler
TransactionBean trans= new TransactionBean();
^
May I know how this problem can be solved?
Thank You.
20 years ago
Map
About Map interface -
which is implemented by HashMap. It is stated that no null object is allowed. But i have tried to add a null valued string but it didn't throw any exception as mentioned in book that it will throw null - pointer exception if we tried to add null object.
Please Help me
thanx
Sp
JVM
When does the JVM exit?

1)After the main method returns.
2)After all the non demons threads created by the application complete.
3)After all the demon threads created by the application complete
4)When a thread executes System.exit();
5)When an uncaught exception is thrown in a non demon thread.
6)When an uncaught exception is thrown in a demon thread.

Answer given is 2, 4, 5 & 6.
Why not 1 ? and Why 6 ?
Thanx
sp
-------

Which of the following are Key-words in java ???.
1)switch
2)class
3)extends
4)null
5)true
6)goto
7)const
8)implements

I know that
case1:: 6),7) are reserved words , so can we include it into key words ???
case2:: 4) is string literals and 5) is boolean literals. can we include it into keywords???
case3:: 1),2),3),8) are keywords

But my doubt is mainly in case1 and case2. I have gone through so many tests but everywhere i have found different things so please anybody help me. I am taking the exam in the next week.

Thanx
sp