刚学struts2.0,在研究一个别人写的小项目。当我新建一个jsp时,不论用到struts2.0的任何标签都不能直接访问这个页面。除非在别的页面用个超链接,先转到Struts.xml配置文件中,在有action 转向那个页面。不知道为什么?
比如:我的jsp页面login.jsp
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>login </title>
</head>
<body>
<s:label>
<tr>
<td>test </td>
</tr>
</s:label>
</body>
</html>
输入:http://localhost:8080/portal/login.jsp
这个页面只要能够用到2.0任何标签都不能直接访问,不用的话就可以访问。 如果用标签,想访问的话就要在Struts.xml中配置 <package name="user" extends="struts-default" namespace="/u">
<action name="login-jsp">
<result>/news/admin/login.jsp </result>
</action>
</package> 输入:http://localhost:8080/portal/u/login-p.jsp才能访问我的login.jsp
我不知道是什么原因,明白的人请给我指点一下。谢谢呀
===========
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">
<!-- context -->
<context-param>
<param-name>contextConfigLocation </param-name>
<param-value>classpath:applicationContext.xml </param-value>
</context-param>
<!-- listener -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener </listener-class>
</listener>
<!-- filter -->
<!-- encodingFilter -->
<filter>
<filter-name>encodingFilter </filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter </filter-class>
<init-param>
<param-name>encoding </param-name>
<param-value>utf-8 </param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter </filter-name>
<url-pattern>*.p </url-pattern>
</filter-mapping>
<!-- hibernateFilter -->
<filter>
<filter-name>hibernateFilter </filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter </filter-name>
<url-pattern>*.p </url-pattern>
</filter-mapping>
<!-- struts2 filter -->
<filter>
<filter-name>struts2 </filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher </filter-class>
</filter>
<filter-mapping>
<filter-name>struts2 </filter-name>
<url-pattern>*.p </url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp </welcome-file>
</welcome-file-list>
</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'> <package name="category" extends="struts-default" namespace="/c">
<action name="stcla" class="categoryAction"
method="showTopCategoryListAjax" />
<action name="scla" class="categoryAction"
method="showCategoryListAjax" />
<action name="scla2" class="categoryAction"
method="showCategoryListAjax2" />
<action name="sccla" class="categoryAction"
method="showCategoryChainListAjax" />
<action name="sc" class="categoryAction"
method="saveCategory">
<interceptor-ref name="token" />
<interceptor-ref name="defaultStack" />
<result name="invalid.token">
/news/success.jsp
</result>
<result name="input">
/news/admin/categoryCreate.jsp
</result>
<result name="CATEGORYACTION_SAVECATEGORY_FAIL">
/news/admin/categoryCreate.jsp
</result>
<result name="CATEGORYACTION_SAVECATEGORY_SUCCESS">
/news/success.jsp
</result>
</action>
<action name="sc1" class="categoryAction"
method="showCategory">
<result name="input">/news/error.jsp </result>
<result name="CATEGORYACTION_SHOWCATEGORY_FAIL">
/news/error.jsp
</result>
<result name="CATEGORYACTION_SHOWCATEGORY_SUCCESS">
/news/admin/categoryShow.jsp
</result>
</action>
<action name="sc2" class="categoryAction"
method="showCategory">
<result name="input">/news/error.jsp </result>
<result name="CATEGORYACTION_SHOWCATEGORY_FAIL">
/news/error.jsp
</result>
<result name="CATEGORYACTION_SHOWCATEGORY_SUCCESS">
/news/admin/categoryUpdate.jsp
</result>
</action>
<action name="dc" class="categoryAction"
method="deleteCategory">
<result name="input">/news/error.jsp </result>
<result name="CATEGORYACTION_DELETECATEGORY_SUCCESS">
/news/success.jsp
</result>
</action>
<action name="uc" class="categoryAction"
method="updateCategory">
<interceptor-ref name="token" />
<interceptor-ref name="defaultStack" />
<result name="invalid.token">
/news/success.jsp
</result>
<result name="input">
/news/admin/categoryUpdate.jsp
</result>
<result name="CATEGORYACTION_UPDATECATEGORY_FAIL">
/news/admin/categoryUpdate.jsp
</result>
<result name="CATEGORYACTION_UPDATECATEGORY_SUCCESS">
/news/success.jsp
</result>
</action>
<action name="*" class="jspRemoteAction">
<result>/news/admin/{1}.jsp </result>
</action>
</package> <package name="user" extends="struts-default" namespace="/u">
<action name="login" class="userAction" method="login">
<result name="success">/news/admin/admin.jsp </result>
</action>
<action name="login-jsp">
<result>/news/admin/login.jsp </result>
</action>
</package> </struts>
=======================
struts.properties
struts.custom.i18n.resources=xwork-message
struts.action.extension=p
struts.locale=zh_CN
比如:我的jsp页面login.jsp
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>login </title>
</head>
<body>
<s:label>
<tr>
<td>test </td>
</tr>
</s:label>
</body>
</html>
输入:http://localhost:8080/portal/login.jsp
这个页面只要能够用到2.0任何标签都不能直接访问,不用的话就可以访问。 如果用标签,想访问的话就要在Struts.xml中配置 <package name="user" extends="struts-default" namespace="/u">
<action name="login-jsp">
<result>/news/admin/login.jsp </result>
</action>
</package> 输入:http://localhost:8080/portal/u/login-p.jsp才能访问我的login.jsp
我不知道是什么原因,明白的人请给我指点一下。谢谢呀
===========
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">
<!-- context -->
<context-param>
<param-name>contextConfigLocation </param-name>
<param-value>classpath:applicationContext.xml </param-value>
</context-param>
<!-- listener -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener </listener-class>
</listener>
<!-- filter -->
<!-- encodingFilter -->
<filter>
<filter-name>encodingFilter </filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter </filter-class>
<init-param>
<param-name>encoding </param-name>
<param-value>utf-8 </param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter </filter-name>
<url-pattern>*.p </url-pattern>
</filter-mapping>
<!-- hibernateFilter -->
<filter>
<filter-name>hibernateFilter </filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter </filter-name>
<url-pattern>*.p </url-pattern>
</filter-mapping>
<!-- struts2 filter -->
<filter>
<filter-name>struts2 </filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher </filter-class>
</filter>
<filter-mapping>
<filter-name>struts2 </filter-name>
<url-pattern>*.p </url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp </welcome-file>
</welcome-file-list>
</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'> <package name="category" extends="struts-default" namespace="/c">
<action name="stcla" class="categoryAction"
method="showTopCategoryListAjax" />
<action name="scla" class="categoryAction"
method="showCategoryListAjax" />
<action name="scla2" class="categoryAction"
method="showCategoryListAjax2" />
<action name="sccla" class="categoryAction"
method="showCategoryChainListAjax" />
<action name="sc" class="categoryAction"
method="saveCategory">
<interceptor-ref name="token" />
<interceptor-ref name="defaultStack" />
<result name="invalid.token">
/news/success.jsp
</result>
<result name="input">
/news/admin/categoryCreate.jsp
</result>
<result name="CATEGORYACTION_SAVECATEGORY_FAIL">
/news/admin/categoryCreate.jsp
</result>
<result name="CATEGORYACTION_SAVECATEGORY_SUCCESS">
/news/success.jsp
</result>
</action>
<action name="sc1" class="categoryAction"
method="showCategory">
<result name="input">/news/error.jsp </result>
<result name="CATEGORYACTION_SHOWCATEGORY_FAIL">
/news/error.jsp
</result>
<result name="CATEGORYACTION_SHOWCATEGORY_SUCCESS">
/news/admin/categoryShow.jsp
</result>
</action>
<action name="sc2" class="categoryAction"
method="showCategory">
<result name="input">/news/error.jsp </result>
<result name="CATEGORYACTION_SHOWCATEGORY_FAIL">
/news/error.jsp
</result>
<result name="CATEGORYACTION_SHOWCATEGORY_SUCCESS">
/news/admin/categoryUpdate.jsp
</result>
</action>
<action name="dc" class="categoryAction"
method="deleteCategory">
<result name="input">/news/error.jsp </result>
<result name="CATEGORYACTION_DELETECATEGORY_SUCCESS">
/news/success.jsp
</result>
</action>
<action name="uc" class="categoryAction"
method="updateCategory">
<interceptor-ref name="token" />
<interceptor-ref name="defaultStack" />
<result name="invalid.token">
/news/success.jsp
</result>
<result name="input">
/news/admin/categoryUpdate.jsp
</result>
<result name="CATEGORYACTION_UPDATECATEGORY_FAIL">
/news/admin/categoryUpdate.jsp
</result>
<result name="CATEGORYACTION_UPDATECATEGORY_SUCCESS">
/news/success.jsp
</result>
</action>
<action name="*" class="jspRemoteAction">
<result>/news/admin/{1}.jsp </result>
</action>
</package> <package name="user" extends="struts-default" namespace="/u">
<action name="login" class="userAction" method="login">
<result name="success">/news/admin/admin.jsp </result>
</action>
<action name="login-jsp">
<result>/news/admin/login.jsp </result>
</action>
</package> </struts>
=======================
struts.properties
struts.custom.i18n.resources=xwork-message
struts.action.extension=p
struts.locale=zh_CN
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货