Struts无法从jsp目录访问jsp
我有一个Struts2应用程序最初jsp页面位于Struts无法从jsp目录访问jsp,jsp,struts2,struts,struts-config,Jsp,Struts2,Struts,Struts Config,我有一个Struts2应用程序最初jsp页面位于WebContent目录的根目录,但是决定添加一个jsp目录来保存jsp页面 由于已完成此操作,因此无法访问页面,并导致HTTP 404错误。我可以访问欢迎文件/jsp/index.jsp。然而,当我发布索引页面时,我得到了http404error-/SEP/hello 我知道代码可以工作,因为一旦jsp页面位于WebContent目录的根目录,它就可以工作了。我想知道如何配置应用程序以利用jsp目录访问jsp页面。下面是目录结构和相关代码的屏幕截
WebContent
目录的根目录,但是决定添加一个jsp目录来保存jsp页面
由于已完成此操作,因此无法访问页面,并导致HTTP 404错误。我可以访问欢迎文件/jsp/index.jsp
。然而,当我发布索引页面时,我得到了http404error-/SEP/hello
我知道代码可以工作,因为一旦jsp页面位于WebContent
目录的根目录,它就可以工作了。我想知道如何配置应用程序以利用jsp目录访问jsp页面。下面是目录结构和相关代码的屏幕截图:
项目结构
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="default" namespace="/jsp/" extends="struts-default">
<action name="hello"
class="org.xxxx.product.registration.model.HelloWorldAction"
method="execute">
<result name="success">/HelloWorld.jsp</result>
</action>
</package>
</struts>
<?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>Struts 2</display-name>
<welcome-file-list>
<welcome-file>/jsp/index.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>/jsp/*</url-pattern>
</filter-mapping>
</web-app>
/HelloWorld.jsp
web.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="default" namespace="/jsp/" extends="struts-default">
<action name="hello"
class="org.xxxx.product.registration.model.HelloWorldAction"
method="execute">
<result name="success">/HelloWorld.jsp</result>
</action>
</package>
</struts>
<?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>Struts 2</display-name>
<welcome-file-list>
<welcome-file>/jsp/index.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>/jsp/*</url-pattern>
</filter-mapping>
</web-app>
支柱2
/jsp/index.jsp
支柱2
org.apache.struts2.dispatcher.ng.filter.strutspreadexecutefilter
支柱2
/jsp/*
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 BY D.Ramdhanie</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>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Hello World</title>
</head>
<body>
Hello World, <s:property value="name"/>
</body>
</html>
你好,世界
D.拉姆达尼《Struts2世界你好》
请输入您的姓名
HelloWorld.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 BY D.Ramdhanie</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>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Hello World</title>
</head>
<body>
Hello World, <s:property value="name"/>
</body>
</html>
你好,世界
你好,世界,
可以通过两种方式在结果中配置JSP:
/jsp/
前缀。
在第二种情况下,JSP与添加到webcontent根以计算绝对路径的操作的名称空间相关。有关名称空间及其配置的更多信息,请参见 jsp目录中的jsp内容 在struts.xml中,您将其称为
<result name="success">/HelloWorld.jsp</result>
/HelloWorld.jsp
这意味着您正在从根级别访问它。默认情况下,用于WebContent目录的“/”。 因此,您应该将结果更新为
<result name="success">/jsp/HelloWorld.jsp</result>
/jsp/HelloWorld.jsp