나는 모든 것을 올바르게했지만 작동하지 않습니다.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>m2r</display-name>
<welcome-file-list>
<welcome-file>weldcome.jsp</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<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>/hello</url-pattern>
</filter-mapping>
</web-app>
strut2.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>
<package name="helloworld" extends="struts-default">
<action name="hello"
class="com.tut.struts2.HelloWorldAction"
method="execute">
<result name="success">/HelloWorld.jsp</result>
</action>
</package>
</struts>
HelloWorld 액션
package com.tut.struts2;
public class HelloWorldAction extends ActionSupport {
private String name;
public String execute() throws Exception {
return "success";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
index.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>
<title>Hello World</title>
</head>
<body>
<h1>Hello World From Struts2</h1>
<form action="hello">
<label for="name">Please enter your name</label><br/>
<input type="text" name="name"/>
<input type="submit" value="Say Hello"/>
</form>
</body>
</html>
매핑 struts.xml
이 잘못된 것 같습니다. 에서 struts.xml
당신은, <result name="success">/HelloWorld.jsp</result>
프레임 워크는 단지를 추가합니다 context path
으로 /HelloWorld.jsp
당신을 찾는 데 사용 HellowWorld.jsp
. 그러나 게시 한 이미지 HelloWorld.jsp
에서 WEB-INF
디렉토리에 있습니다. 이것이 struts가 jsp를 찾을 수없는 이유입니다. 현재 매핑을 반영 하도록 jsp를 다시 매핑 struts.xml
하거나의 위치를 변경합니다 HelloWorld.jsp
. 나는 이것이 당신의 문제를 해결할 것이라고 생각합니다.
편집 변경 struts2.xml
에struts.xml
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다