Your code is different in my code... I cant figure out whats the error in that but If you want to fill a bean heres some simple codes... JSP
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="myServlet" method="post">
<input type="text" name="name"/>
<input type="submit"/>
</form>
</body>
</html>
Servlet
package samplePack;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class myServlet
*/
public class myServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/\*\*
\* @see HttpServlet#HttpServlet()
\*/
public myServlet() {
super();
// TODO Auto-generated constructor stub
}
/\*\*
\* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
\*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/\*\*
\* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
\*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
myBean bean = new myBean(request.getParameter("name"));
System.out.println(bean.getName());
}
}
BEAN
package samplePack;
public class myBean {
private String name = null;
public myBean(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
hope this help...
modified on Monday, April 5, 2010 10:54 PM