Hi
I'm trying to do a simple web app. A jsp with a form fills a beans properties. A servlet then uses that bean data but I can't seem to get it to work.
This is a simplified version.....
my jsp page is as follows
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<%@ taglib prefix="c" uri=" %>
<jsp:useBean id="test" scope="session" class="servletlesson.TestBean" >
<jsp:setProperty name="test" property="*" />
</jsp:useBean>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form method="post" action="test">
<table width="" border="0" cellspacing="" cellpadding="">
<tr>
<td>test</td>
<td><input name="test" type="text" ></td>
</tr>
<tr>
<td><input type="submit" value="Submit" name="submit" ></td>
</tr>
</table>
</form>
</body>
</html>
my bean is
import java.io.*;
public class TestBean implements Serializable{
private String test;
public TestBean() {
}
public void setTest(String aTest){
this.test=aTest;
}
public String getTest(){
return test;
}
}
and my servlet is
public class TestServlet extends HttpServlet {
public void init(){
}//init
public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException{
HttpSession sess=req.getSession();
TestBean test=(TestBean)sess.getAttribute("test"
;
PrintWriter out=res.getWriter();
out.println("This is a test "+test.getTest());
}//doPost
}
Am I going about this the wrong way?? Is it wrong to share data between beans and servlets in this way?
All i get from test.getTest() is null whereas I want to return my form value that the user types in.
If anyone can help I'll be eternally grateful.
Thanks a lot,
B
I'm trying to do a simple web app. A jsp with a form fills a beans properties. A servlet then uses that bean data but I can't seem to get it to work.
This is a simplified version.....
my jsp page is as follows
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<%@ taglib prefix="c" uri=" %>
<jsp:useBean id="test" scope="session" class="servletlesson.TestBean" >
<jsp:setProperty name="test" property="*" />
</jsp:useBean>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form method="post" action="test">
<table width="" border="0" cellspacing="" cellpadding="">
<tr>
<td>test</td>
<td><input name="test" type="text" ></td>
</tr>
<tr>
<td><input type="submit" value="Submit" name="submit" ></td>
</tr>
</table>
</form>
</body>
</html>
my bean is
import java.io.*;
public class TestBean implements Serializable{
private String test;
public TestBean() {
}
public void setTest(String aTest){
this.test=aTest;
}
public String getTest(){
return test;
}
}
and my servlet is
public class TestServlet extends HttpServlet {
public void init(){
}//init
public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException{
HttpSession sess=req.getSession();
TestBean test=(TestBean)sess.getAttribute("test"
PrintWriter out=res.getWriter();
out.println("This is a test "+test.getTest());
}//doPost
}
Am I going about this the wrong way?? Is it wrong to share data between beans and servlets in this way?
All i get from test.getTest() is null whereas I want to return my form value that the user types in.
If anyone can help I'll be eternally grateful.
Thanks a lot,
B