LoginSignup
0
0

More than 3 years have passed since last update.

インスタンスをインポートして別画面で使う

Last updated at Posted at 2020-10-26

ちょっと躓いたのでメモ

超基本的な事と思うけど、PHPには無かった事

クラスのインスタンス化。

これは至る所で紹介されているので簡単に見つけれた。

//顧客情報のインスタンス化
Customer customer = new Customer();

こんな感じでnew してやればインスタンス化できる。

しかし画面Aでインスタンス化したものを画面Bでnewせずに使うにはどうすればよいか?

迷ったけどやってみたら結構簡単にできました。

画面A(Java)でsetAttributeして

request.setAttribute("customer", customer);

画面B(JSP)でインポートして受け取る

<%@ page import="pizzaOrderForm.customer.*" %>
Customer customer = (Customer)request.getAttribute("customer");

これでインスタンス化したcustomerを別画面でも使えるようになりました。

Java道は難しいな…

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0