<?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>*.action</url-pattern>
</filter-mapping> <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<!--
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
-->
</web-app>
以上是我的xml配置文件<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="struts2" extends="struts-default">
<action name ="login" class="com.shop.action.LoginAciton">
<result name ="input">/login.jsp</result>
<result name ="success">/result.jsp</result>
<result name ="failer">/login.jsp</result>
</action>
</package>
</struts> 以上struts配置
package com.shop.action;import com.opensymphony.xwork2.ActionSupport;public class LoginAciton extends ActionSupport{
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassWord() {
return password;
}
public void setPassWord(String password) {
this.password = password;
}
public String execute() throws Exception
{
if ("hello".equals(this.getUsername().trim())
&& "world".equals(this.getPassWord().trim()))
{
return "success";
}
else
{
this.addFieldError("username", "username or password error");
return "failer";
} }
@Override
public void validate()
{
if (null == this.getUsername() || "".equals(this.getUsername().trim()))
{
this.addFieldError("username", "username required");
}
if (null == this.getPassWord() || "".equals(this.getPassWord().trim()))
{
this.addFieldError("password", "password required");
}
}}loginaction文件
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="s" uri="/struts-tags" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>登陆</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<s:form action="login">
<s:textfield name="username" label="username"></s:textfield>
<s:password name="password" label="password"></s:password>
<s:submit label="submit"></s:submit>
</s:form>
</body>
</html>
login的jsp页面
以上就是现已编写代码,我调试了1天也没弄出点名堂,还求大家指点,最好再回帖时给我一些初学SSH2的人的建议,谢谢各位了
<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>*.action</url-pattern>
</filter-mapping> <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<!--
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
-->
</web-app>
以上是我的xml配置文件<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="struts2" extends="struts-default">
<action name ="login" class="com.shop.action.LoginAciton">
<result name ="input">/login.jsp</result>
<result name ="success">/result.jsp</result>
<result name ="failer">/login.jsp</result>
</action>
</package>
</struts> 以上struts配置
package com.shop.action;import com.opensymphony.xwork2.ActionSupport;public class LoginAciton extends ActionSupport{
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassWord() {
return password;
}
public void setPassWord(String password) {
this.password = password;
}
public String execute() throws Exception
{
if ("hello".equals(this.getUsername().trim())
&& "world".equals(this.getPassWord().trim()))
{
return "success";
}
else
{
this.addFieldError("username", "username or password error");
return "failer";
} }
@Override
public void validate()
{
if (null == this.getUsername() || "".equals(this.getUsername().trim()))
{
this.addFieldError("username", "username required");
}
if (null == this.getPassWord() || "".equals(this.getPassWord().trim()))
{
this.addFieldError("password", "password required");
}
}}loginaction文件
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="s" uri="/struts-tags" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>登陆</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<s:form action="login">
<s:textfield name="username" label="username"></s:textfield>
<s:password name="password" label="password"></s:password>
<s:submit label="submit"></s:submit>
</s:form>
</body>
</html>
login的jsp页面
以上就是现已编写代码,我调试了1天也没弄出点名堂,还求大家指点,最好再回帖时给我一些初学SSH2的人的建议,谢谢各位了
org.xml.sax.SAXParseException: Open quote is expected for at what?
web.xml<?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"> <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param>
<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>*.action</url-pattern>
</filter-mapping> <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping> <listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener> <welcome-file-list>
<welcome-file>login.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.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="struts2" extends="struts-default">
<action name ="login" class="com.shop.action.LoginAction">
<result name ="input">/login.jsp</result>
<result name ="success">/result.jsp</result>
<result name ="failer">/login.jsp</result>
</action>
</package>
</struts> applicationContext.xml<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
</beans>
LoginAction.javapackage com.shop.action;import com.opensymphony.xwork2.ActionSupport;@SuppressWarnings("serial")
public class LoginAction extends ActionSupport{
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassWord() {
return password;
}
public void setPassWord(String password) {
this.password = password;
}
public String execute() throws Exception
{
if ("hello".equals(this.getUsername().trim())
&& "world".equals(this.getPassWord().trim()))
{
return "success";
}
else
{
this.addFieldError("username", "username or password error");
return "failer";
} }
@Override
public void validate()
{
if (null == this.getUsername() || "".equals(this.getUsername().trim()))
{
this.addFieldError("username", "username required");
}
if (null == this.getPassWord() || "".equals(this.getPassWord().trim()))
{
this.addFieldError("password", "password required");
}
}}
login.jsp<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>登陆</title>
</head>
<body>
<s:form action="login" method="post">
<s:textfield name="username" label="username"></s:textfield>
<s:password name="password" label="password"></s:password>
<s:submit label="submit"></s:submit>
</s:form>
</body>
</html>
PS:是LoginAction不是 LoginAciton
<s:textfield name="username" label="username"></s:textfield>
<s:password name="password" label="password"></s:password>
<s:submit label="submit"></s:submit>
</s:form>
action="login" 在哪里? 都没有吧?
应该是org.xml.sax.SAXParseException: Open quote is expected for at{1}不过我现在tomcat已经不报这个错了,我把tomcat的server.xml中的context修改了一下
现在则是严重: Exception starting filter struts2
Class: com.opensymphony.xwork2.spring.SpringObjectFactory
File: SpringObjectFactory.java
Method: getClassInstance
Line: 220 - com/opensymphony/xwork2/spring/SpringObjectFactory.java:220:-1
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:428)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4038)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4692)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:701)
at org.apache.catalina.startup.Catalina.start(Catalina.java:585)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.NullPointerException
at com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(SpringObjectFactory.java:220)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyResultType(XmlConfigurationProvider.java:530)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addResultTypes(XmlConfigurationProvider.java:501)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:457)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:275)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:111)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:204)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:371)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:415)
... 20 more
2011-1-23 15:26:57 org.apache.catalina.core.StandardContext start
严重: Error filterStart
2011-1-23 15:26:57 org.apache.catalina.core.StandardContext start
严重: Context [/struts] startup failed due to previous errors
2011-1-23 15:26:57 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
严重: The web application [/struts] created a ThreadLocal with key of type [com.opensymphony.xwork2.inject.ContainerImpl$10] (value [com.opensymphony.xwork2.inject.ContainerImpl$10@101f287]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@d9973a]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
2011-1-23 15:26:57 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
严重: The web application [/struts] created a ThreadLocal with key of type [com.opensymphony.xwork2.inject.ContainerImpl$10] (value [com.opensymphony.xwork2.inject.ContainerImpl$10@1578426]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@a4effe]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
我框架使用的是hibernate3.3,spring3.x,全都是myeclipse8.6自带的,struts-2.2.1.1-all是我自己下的配置的,jdk是我在oracle网站上下来的最新的JAVA SE 6,用的glassfishv3文件夹里的jdk
我框架使用的是hibernate3.3,spring3.x,全都是myeclipse8.6自带的,struts-2.2.1.1-all是我自己下的配置的,jdk是我在oracle网站上下来的最新的JAVA SE 6,用的glassfishv3文件夹里的jdk