首页 > struts2中访问路径的问题

struts2中访问路径的问题

项目目录:

sturts.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="/path" extends="struts-default">
        <action name="index">
            <result>/default.jsp</result>
        </action>
    </package>

</struts>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    
  <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>
</web-app>

default.jsp

<?xml version="1.0" encoding="GB18030" ?>
<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
    <%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030" />
<title>DefaultAction</title>
</head>
<body>
Default Action!
</body>
</html>

文件代码如上,请问:

为什么加上项目名称的时候会出错?不是一般访问路径都是含有项目名称的么?


你的配置是正确的。
使用“localhost:8080/ProjectName”访问不了,是和开发工具有关。
在Intellij Idea中,默认情况下,你可以直接使用“localhost:8080/”访问你的项目,比较方便。
如果想加上项目名访问,“localhost:8080/ProjectName”,需要配置Intellij idea,

【热门文章】
【热门文章】