我是个超级新手,看了好多都是说路径问题,但是我还是不会调,能不能指条明路?ACTION是放在了一个叫com的包里,然后工程名是FirstTest,请问我需要改进哪里?非常感谢。这是stuts.xml页面:
<package name="body" extends="struts-default" namespace="/">
<action name="/com/NewsList" class="com.NewsAction" method="getAllNews">
<result name="index">/WEB-INF/jsp/index.jsp</result>
</action>这是web.jsp代码:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<!-- Spring config file -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/appctx.xml</param-value>
</context-param> <!--Startup spring-->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- Config 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>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
这是index.jsp的部分内容:
<body>
<s:form name="NewsList" action="/com/NewsList.do" >
<center><br />
<h2>NEWSLIST</h2>
<table border="1">
<tr bgcolor="#33CCFF">
<td align="center">NEWSID</td>
<td align="center">NEWSTITLE</td>
<td align="center">NEWSCONTENT</td>
<td align="center">NEWSLASTTIME</td>
<td align="center">EDITNEWS</td>
<td align="center">DELETNEWS</td>
</tr>
<package name="body" extends="struts-default" namespace="/">
<action name="/com/NewsList" class="com.NewsAction" method="getAllNews">
<result name="index">/WEB-INF/jsp/index.jsp</result>
</action>这是web.jsp代码:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<!-- Spring config file -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/appctx.xml</param-value>
</context-param> <!--Startup spring-->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- Config 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>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
这是index.jsp的部分内容:
<body>
<s:form name="NewsList" action="/com/NewsList.do" >
<center><br />
<h2>NEWSLIST</h2>
<table border="1">
<tr bgcolor="#33CCFF">
<td align="center">NEWSID</td>
<td align="center">NEWSTITLE</td>
<td align="center">NEWSCONTENT</td>
<td align="center">NEWSLASTTIME</td>
<td align="center">EDITNEWS</td>
<td align="center">DELETNEWS</td>
</tr>
解决方案 »
- MyEclipse7.0应用weblogic10发布java web project 问题
- hibernate 一级缓存
- jsp生成xml文件时, 会在文件头产生的空白行
- Java里面文件的命名有$连接两个类名
- 一个值得关注的事件控制
- 初级问题
- 请高手看看我的关于函数调用的错误
- weblogic7神奇问题,请各位看看怎么回事???在线等待!!!
- 怎样在j2ee应用服务器(Sun公司的)中配置数据DataSource的JNDI名字,使得可以通过查找获得Connection?
- 这个学生成绩管理系统为什么运行不了,代码那里出了问题,求解答
- 请问onItemClick函数中的每个参数是什么意思?
- 科学计数法求解!
但是看你struts.xml里面配的index.jsp文件又是放在/WEB-INF/jsp/目录下面的,我不太清楚你是不是两个目录下面都有index.jsp文件,但如果不是,建议你在web目录下放一个index.jsp
1.你把stuts.xml和index.jsp中的action都改成NewsList.action
2.你要确定web-inf/jsp文件夹下面要有index.jsp
3(也是最重要的)struts默认拦截*.action,对于新手,你最好<url-pattern>*.action</url-pattern>
然后估计就没问题了
后面不需要加.do
比如<action name="NewsList" class="com.NewsAction" method="getAllNews">
后面不需要加.do