简单的struts示例找不到jsp

时间:2016-05-07 02:29:16

标签: jsp struts2

我有一个struts示例,我能够访问index.jsp,但是无法访问success.jsp并导致HTTP 404错误。有人可以帮助我,提前谢谢。 这是我的项目结构。 Project Structure

的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">

  <welcome-file-list>
    <welcome-file>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>/*</url-pattern>
  </filter-mapping>

</web-app>

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>
    <package name="default" extends="struts-default">
        <action name="hello" class="com.action.IndexAction">
            <result name="success">/views/success.jsp</result>
        </action>
    </package>
</struts>

的success.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'success.jsp' starting page</title>
  </head>

  <body>
    <h2><s:property value="message"/></h2><br>
  </body>
</html>

IndexAction.java

package com.action;

import com.opensymphony.xwork2.ActionSupport;

public class IndexAction extends ActionSupport {
    private static final long serialVersionUID = 1L;
    private static final String MESSAGE = "struct is running";
    private String message = "";

    @Override
    public String execute() throws Exception {
        setMessage(MESSAGE);
        return SUCCESS;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}

1 个答案:

答案 0 :(得分:1)

根据您的应用程序结构,您可能已将 success.jsp 置于 / WEB-INF / views 下。所以

document.getElementById('selValue').value=Your Value; $('#selValue').selectpicker('refresh'); 将是

<result name="success">/views/success.jsp</result>

修改:

<强> struts.xml中:

<result name="success">/WEB-INF/views/success.jsp</result>