2009-09-22 30 views
2

In my struts2 application I want to open a new window when user click on a link available on jsp page.window.open()と<a href="'> in Struts2

I don’t want to user window.open() function of javascript and anchor tag i.e <s:a href=””>.

Onclick control should goto action class, after some processing there it should open a new window.

Please help if it is possible.

答えて

4

Well, if you don't want to use neither anchor nor window.open() (why?) your only other option is to use "target" attribute on a form and submit it:

<form name="..." method="..." action="..." target="_blank"> 

Be warned that:

  1. It's deprecated in HTML 4.01 and not supported in XHTML strict.
  2. That window WILL open and control will be transferred to it. You can't suddenly decide in your action that you don't want to open that window; the best you can do is try to close it.

Details on "target" attribute are hereを使用せずに新しいウィンドウを開く方法。もう一度、window.open()と<a href="..." target="...">の両方がより良い解決策のように見えます - なぜあなたはそれらを使用することに反対ですか?

+0

ChssPly76、Thanks 4 ur reply。実際には、新しいウィンドウを開く前に、データベースからいくつかのエントリを取得したいし、これらのエントリは新しい開いたウィンドウ(.jsp)に表示されます。 as、window.open()は新しいウィンドウを直接開きますので無駄です。あなたの返信を見る前に、 のようなアンカータグを使用しました。 GoToBlog(2) よく動いています。しかし今は新しいウィンドウサイズを修正したいので、Internet Explorerのメニュー、アドレスバー、リフレッシュなどのヘルプを表示すべきではありません。 – vivmal

+1

ウィンドウサイズ/属性を制御する唯一の方法は、window.open()関数を使用する方法です。どうしてあなたが "役に立たない"と言っているのか分かりません。window.open()メソッドのどのパラメータであれ、JSPにURLを渡すことができます。 'window.open(" http://mysite.com/full_path/someAction?autoId=autoId "、"ブログ "、"メニューバー= 0、ステータス= 0、幅= 350、高さ= 250 ")。あなたのアクションが呼び出され、出力をそのウィンドウにレンダリングする前に、DBからの読み込みのような何でもできます。 – ChssPly76

+0

私はChssPly76に同意しますが、最初はwindow.open( "url")のようなURLを提供できません。actionNameのみを提供しなければならず、そのアクションはstruts.xmlにあります。クラス(.java)であり、そのアクションクラスはDBでいくつかの処理を行い、エラー/入力/成功などをstruts.xmlに返すと、struts.xmlはどの新しいウィンドウが開くかを宣言します(つまりjspページ)。提案する...その実行中の面白い... – vivmal

関連する問題