2016-07-05 6 views
-1

이미지가 포함 된 jsp 페이지가 있고 이미지를 클릭하면 다른 JSP 페이지로 이동해야합니다. struts2.html에서이 작업을 수행하기 전에 이미지 동작을 추가하기 전에 정상적으로 작동하고있었습니다. .이미지를 클릭하면 struts 동작이 발생합니다.

의 login.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
    <%@ taglib prefix="s" uri="/struts-tags"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Insert title here</title> 
</head> 
<body> 
<s:form action="login" method="post"> 
<s:textfield name="id" label="Employee Id"></s:textfield> 
<s:textfield name="name" label="Employee Name"></s:textfield> 
<s:submit value="save"></s:submit> 
</s:form> 
</body> 
</html> 

LoginAction.java :

package login; 

public class LoginAction { 

    private int id; 
    private String name; 

    public int getId() { 
     return id; 
    } 

    public String getName() { 
    return name; 
    } 

    public String execute(){ 
     return "success"; 
} 
} 

Struts.xml

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE struts PUBLIC 
    "-//Apache Software Foundation//DTD Struts Configuration 2.0.//EN" 
    "http://struts.apache.org/dtds/struts-2.0.dtd"> 
<struts> 
<constant name="struts.devMode" value="true" /> 
    <package name="login" extends="struts-default" namespace="/" > 
    <default-action-ref name="upload" /> 



    <action name="login" class="login.LoginAction" method="execute"> 
<result name="success">products.jsp</result> 
</action> 

<action name="click" class="login.ItemAction" method="execute"> 
<result name="success">productdetails.jsp</result> 
</action> 

    </package> 
</struts> 

의 web.xml :

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> 
    <display-name>dhanya</display-name> 


    <filter> 
     <filter-name>struts2</filter-name> 

    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> 


    </filter> 

    <filter-mapping> 
     <filter-name>struts2</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 



    <welcome-file-list> 
    <welcome-file>Login.jsp</welcome-file> 
    </welcome-file-list> 
    </web-app> 

Products.jsp :

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
    <%@ taglib prefix="s" uri="/struts-tags"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>product images</title> 

</head> 
<div align="center" style="white-space: nowrap;word-wrap:break-word;"> 
    <%@ include file="Header.jsp" %> 

    </div> 
<body> 

<a href="<s:url action="click"/>"></a><img src="images/bp.jpg" class="tooltip" title="BP monitor" id="BP monitor"> </a> 
<a href="<s:url action="click"/>">"><img src="images/sethescope.jpg" class="tooltip" title="sethescope" id="sethescope"></a> 

    </body> 
    <div align="center" style="white-space: nowrap;word-wrap:break-word;"> 
    <%@ include file="Footer.jsp" %> 

    </div> 

</html> 

ItemAction.java

package login; 

public class ItemAction { 
    public String execute(){ 
      return "success"; 
    } 

} 

enter image description here

답변

0

당신은 단순히 앵커와 관련된 이미지를 원하는 경우, 다음과 같이, 당신은 그것을 할 수 있습니다 :

<s:url var='imageUrl' action='yourActionName'/> 
<s:a href='%{#imageUrl}'><img src='<s:url value="images/yourimage.jpg"/>'/></s:a> 

이름이 지정된 URL을 생성하고 이름이 지정된 URL을 참조합니다. n Struts2 앵커 태그의 href 속성과 인라인 URL을 사용하여 표시 할 이미지에 대한 올바른 컨텍스트 기반 경로를 참조합니다.

그러나 질문에 대해서는 products.jsp에 포함 된 첫 번째 이미지 링크에 빗나간 </a>이있는 것 같습니다.

+0

은 내가 products.jsp 페이지에 두 개의 이미지가 같은 고객이 필요로 할 때 나는 하나 개의 이미지를 클릭하면, 그것은 JSP 액션 전화를 page.how 다른 이동한다 이것에 대한 struts2 –

+0

사람이 나를 도울 수있다, 그것은 매우 급하다 –

0

처음에는 strtus.xml 파일에 작업을 정의하고 해당 작업 클래스를 살펴보고이 방법으로 작업을 호출 할 수 있습니다. 내가 복귀 성공 메시지와 함께 XML 파일에 정의 .IT 확실히 작동 확인했다 Products.jsp

<a href="<s:url action="cancel.action" />"><img src="image/1.png" class="tooltip" height="42" width="42" title="BP monitor" id="BP monitor" > </a> 

<a href="<s:url action="hello.action"/>"><img src="image/2.jpg" height="42" width="42" class="tooltip" title="sethescope" id="sethescope"></a> 

및 strtus.xml

<action name="cancel" 
     class="com.test.CancelAction" 
     method="execute"> 
     <result name="success">/Cancel.jsp</result> 
    </action> 

    <action name="hello" 
     class="com.test.ApproveAction" 
     method="execute"> 
     <result name="success">/Approve.jsp</result> 
    </action> 

및 정의 클래스에서

. 죄송합니다. 테스트 목적으로 다른 이미지를 찍었습니다. 고마워하고 의심의 여지가 여기에 물어보십시오. strtus.xml에서 <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>

변경 <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

+0

: 여전히 작동하지 않습니다. 나는 아래의 오류가 발생했습니다 : 심각 : 필터 struts2 시작 예외 구성을로드 할 수 없습니다. - action - file :/C : /Users/RajD/Documents/java/apache-tomcat-8.0.36-windows-x64/apache-tomcat-8.0.36/webapps/dhanya/WEB-INF/classes/struts.xml : 19 : 26 –

+0

@DhanyaRaj Strtus.xml에서 필터 URL을 변경하는 답변을 업데이트하여 내 게시물의 업데이트 된 URL을 확인하십시오. –

+0

@DhanyaRaj 당신은 시도 했습니까? 업데이트 된 답변 –

관련 문제