我是初学struts2.0,今天手动配置一个hello world的程序,不知道为什么已启动Tomcat6就报一个严重错误:严重: Exception starting filter struts2
file:/D:/Apache%20Software%20Foundation/Tomcat%206.0/webapps/strutsProj/WEB-INF/classes/struts.xml:1:34
.....
Caused by: White space is required before the encoding pseudo attribute in the XML declaration. - file:/D:/Apache%20Software%20Foundation/Tomcat%206.0/webapps/strutsProj/WEB-INF/classes/struts.xml:1:34
... 34 more
Caused by: org.xml.sax.SAXParseException: White space is required before the encoding pseudo attribute in the XML declaration.
....我的工程strutsProj放在Tomcat6.0的webapps下,目录结构如下:strutsProj
--> WEB-INF
--> classes
--> struts.xml
--> hr/javaeye/test/LoginAction.class
--> lib (struts2-core-2.0.6,ognl-2.6.11,freeer-2.3.8,xwork-2.0.1,commons-logging-1.0.4五个jar)
--> web.xml
--> index.jsp
--> error.jsp
--> welcome.jsp
web.xml配置
<?xml version="1.0" encoding="GBK"?><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">
<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>
</web-app>struts.xml配置
<?xml version="1.0"encoding="GBK"?><!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd"><struts>
<package name="strutsProj" extends="struts-default">
<action name="Login" class="hr.javaeye.test.LoginAction">
<result name="error">/error.jsp</result>
<result name="success">/welcome.jsp</result>
</action>
</package>
</struts>
LoginAction代码:
package hr.javaeye.test;public class LoginAction {
private String username;
private String password;
public LoginAction(String username,String password){
this.username=username;
this.password=password;
}
public String getUsername(){
return this.username;
}
public void setUsername(String username){
this.username=username;
}
public String getPassword(){
return this.password;
}
public void setPassword(String password){
this.password=password;
}
public String execute() throws Exception{
if(getUsername().equals("single")&&getPassword().equals("111"))
return "success";
else return "error";
}
}
奇怪的事,我把struts.xml放在WEB-INF/classes的目录下,启动Tomcat就出现严重错误。如果把struts.xml放在WEB-INF目录下,则启动Tomcat不会出错,但是运行登陆界面的时候,提示没有找到action。不是说struts2.0的struts.xml要放在classes下面的吗,本人是初学者,请大伙指点,谢谢大家。
file:/D:/Apache%20Software%20Foundation/Tomcat%206.0/webapps/strutsProj/WEB-INF/classes/struts.xml:1:34
.....
Caused by: White space is required before the encoding pseudo attribute in the XML declaration. - file:/D:/Apache%20Software%20Foundation/Tomcat%206.0/webapps/strutsProj/WEB-INF/classes/struts.xml:1:34
... 34 more
Caused by: org.xml.sax.SAXParseException: White space is required before the encoding pseudo attribute in the XML declaration.
....我的工程strutsProj放在Tomcat6.0的webapps下,目录结构如下:strutsProj
--> WEB-INF
--> classes
--> struts.xml
--> hr/javaeye/test/LoginAction.class
--> lib (struts2-core-2.0.6,ognl-2.6.11,freeer-2.3.8,xwork-2.0.1,commons-logging-1.0.4五个jar)
--> web.xml
--> index.jsp
--> error.jsp
--> welcome.jsp
web.xml配置
<?xml version="1.0" encoding="GBK"?><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">
<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>
</web-app>struts.xml配置
<?xml version="1.0"encoding="GBK"?><!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd"><struts>
<package name="strutsProj" extends="struts-default">
<action name="Login" class="hr.javaeye.test.LoginAction">
<result name="error">/error.jsp</result>
<result name="success">/welcome.jsp</result>
</action>
</package>
</struts>
LoginAction代码:
package hr.javaeye.test;public class LoginAction {
private String username;
private String password;
public LoginAction(String username,String password){
this.username=username;
this.password=password;
}
public String getUsername(){
return this.username;
}
public void setUsername(String username){
this.username=username;
}
public String getPassword(){
return this.password;
}
public void setPassword(String password){
this.password=password;
}
public String execute() throws Exception{
if(getUsername().equals("single")&&getPassword().equals("111"))
return "success";
else return "error";
}
}
奇怪的事,我把struts.xml放在WEB-INF/classes的目录下,启动Tomcat就出现严重错误。如果把struts.xml放在WEB-INF目录下,则启动Tomcat不会出错,但是运行登陆界面的时候,提示没有找到action。不是说struts2.0的struts.xml要放在classes下面的吗,本人是初学者,请大伙指点,谢谢大家。
解决方案 »
- 关于j2ee调用c++的方法的问题
- 关于java以下内容是否需要学习下?
- 继承SqlMapClientDaoSupport的DAO类,怎么测试它?
- spring里声明一个接口,要怎么写
- 推荐个好用的分页标签
- openSessionInView怎么配置
- JQuery ajax 访问action为什么出现无action?
- 一个问题半天没解决了,各位大虾帮帮忙吧,跪求
- 为什么tomcat5.0运行一段时间后服务自动停止
- 报Io 异常: The Network Adapter could not establish the connection 的真正问题在哪?
- Web服务器Jboss问题...
- 救命
我的工程strutsProj放在Tomcat6.0的webapps下,目录结构如下:strutsProj
--> WEB-INF
--> classes
--> struts.xml
--> hr/javaeye/test/LoginAction.class
--> lib (struts2-core-2.0.6,ognl-2.6.11,freeer-2.3.8,xwork-2.0.1,commons- logging-1.0.4五个jar)
--> web.xml
--> index.jsp
--> error.jsp
--> welcome.jsp
再看看你的struts.xml
<?xml version="1.0" encoding="UTF-8"?> encoding前要有空格,你的没有,加上试试看
有问题。应该是
<?xml version="1.0" encoding="GBK"?>
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:186)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:41)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:497)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:421)
因为控制器的名字叫LoginAction,因此红字的部分应该大些: Login.action