java获取form,从JSP(form)获取信息到Java Bean

I have a JSP form. My requirement is to get this form's data and create a java beans object on the server side.

Example: my form has fields like Name, SSN, EMAIL & Phone Number

public class Test {

long ssv= 1282199222991L;

long phone= 4082224444L;

String email = "abcdef@yahoo.com";

String name="abcdef"

}

From the knowledge i have , i was thinking to create bean object using servlet, which is created out of JSP, at the server side. My question is how i access this "server created" servlet for getting the variables data?

PS: I am beginner in web programing & server side scripting. Please let me know if the question is not clear. Any information would very valuable for me. Please do let me know if i am thinking in the right way. Trailer Thanks!

解决方案

The JSP should indeed submit the form to the servlet. The servlet should indeed create the bean and use it to transfer the submitted data through the necessary layers (save in database using DAO class and/or redisplay in result JSP after submit).

Here's a kickoff example of how the JSP should look like:

And here's how you could write the doPost() method of the servlet which is listening on an url-pattern of /register.

String name = request.getParameter("name");

String email = request.getParameter("email");

String phone = request.getParameter("phone");

String ssv = request.getParameter("ssv");

// Do the necessary validations here and then ..

User user = new User(name, email, phone, Long.valueOf(ssv));

// Now you have an User javabean with the necessary information.

// Do with it whatever you want. E.g. saving in database.

userDAO.save(user);

See also:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值