2009-09-22 7 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, 감사 4 ur 답장. 사실, 새 창을 열기 전에 데이터베이스에서 항목을 가져오고 싶습니다. 그런 다음이 항목은 새 창 (.jsp)에 나타납니다. as, window.open()은 쓸모없는 새로운 윈도우를 직접 엽니 다. 예, 회신을보기 전에 앵커 태그를 사용했습니다. GoToBlog (2) 잘 실행 중입니다. 하지만 이제는 새 창 크기를 수정하고 인터넷 탐색기 메뉴, 주소 표시 줄, 새로 고침 등의 정보를 표시해서는 안됩니다. – vivmal

+1

윈도우 크기/속성을 제어하는 ​​유일한 방법은 window.open() 함수를 사용하는 것입니다. 왜 "쓸모없는"이유인지 모르겠습니다. window.open() 메소드에 대한 매개 변수를 사용하여 JSP에 URL을 전달할 수 있습니다 (예 : 'window.open ("http://mysite.com/full_path/someAction?autoId=autoId", "blogs", "menubar = 0, status = 0, width = 350, height = 250"). 당신의 행동이 호출 될 것이고 그 결과물을 그 창에 표시하기 전에 당신이 원하는대로 할 수 있습니다. – ChssPly76

+0

ChssPly76에 동의하지만 처음에는 window.open ("url")과 같은 URL을 제공 할 수 없으며 actionName 만 제공해야하며 해당 동작은 내 struts.xml로 이동합니다. xml은 해당 컨트롤이 어떤 동작을 수행할지 결정합니다 클래스 (.java)와 그 작업 클래스는 DB를 사용하여 일부 처리를 수행하고 struts.xml에 error/input/success 등을 반환하면 struts.xml은 어떤 새 창 (예 : JSP 페이지)을 열 것인지를 선언합니다. 제안 ... 실행중인 흥미로운 ... – vivmal

관련 문제