Servlet里面的传值,与在jsp中的接受值的问题!

大家可能看不清楚,这是我自己写的。等自己有时间来解决。

 

1、Servlet的类的写法

 

 

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ServletPerson extends HttpServlet{

 @Override
 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
   throws ServletException, IOException {
  // TODO Auto-generated method stub
  this.doPost(req, resp);
 }

 @Override
 protected void doPost(HttpServletRequest req, HttpServletResponse resp)
   throws ServletException, IOException {
  String path="JGPerson.jsp";
      String uname=req.getParameter("name");
      String uage=req.getParameter("age");
     
               Person p=new Person();
               p.setAge(Integer.parseInt(uage));
               p.setName(uname);
              
               req.setAttribute("person", p);
              
               req.getRequestDispatcher(path).forward(req, resp);
               
         }
 

}

 

2、接受值的jsp页面的写法

 

<%@ page language="java" contentType="text/html"
    pageEncoding="utf-8"%>
<html>
<head>
<title>this first jsp and Servlet</title>
</head>
<body>
<%=request.getAttribute("person").getClass()%><br>

姓名:${person.name}<br>
年龄:${person.age}<br>

</body>
</html>

 

 

3、问题是:我不想通过$表达式,得到Person类里面的值,也就是页面传过来的。

还有别的方法吗?我既然可以得到<%=request.getAttribute("person").getClass()%><br>

我能不能通过get方法,拿到值吗?

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值