解决方案 »
- HQL 联合查询问题 求教
- 【紧急】求指点:如何根据MAC地址获取IP地址
- 级联查询(回答就有分)
- SSH整合时出的错误,高手给看一下啊
- java如何读取Oracle中Long型数据?
- EJB新手问题
- 在windows server 2003 sp2中,如何设置startup.bat为开机进程?看不到黑色dos窗体的那种。
- 如何用DREAMWEAVER和JSP加TOMCAT开发WEB程序?
- 【Struts 资源文件(*.properties)配置方法 help!】
- java
- java和c#通过webservice交互哪个做服务端哪个做客户端好
- spring注入,但action中service为空,附代码 求帮助
<form action="login.action" method="get">
<action name="login" method="logins" class="cn.test.springTest.LoginAction">
</action>
几乎一样的代码,这次确成功了。。不知道是不是编译工具的大姨妈来了。。
崩溃<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
this form
<form action="loginsss" method="get">
姓名:<input name="name" type="text"></input><br>
密码:<input name="password" type="password"></input><br>
<input type="submit" value="注册"></input>
</form>
</body>
</html><struts>
<package name="myPackage" namespace="/resources" extends="struts-default">
<!-- <default-class-ref class=""/> -->
<global-results>
<result name="success">/resources/loginsuccess.jsp</result>
<result name="error">/resources/error.html</result>
</global-results>
<action name="loginsss" method="logins" class="cn.test.springTest.LoginAction">
</action>
<action name="register" method="execute" class="cn.test.springTest.RegisterAction">
</action>
</package>
</struts>
public class LoginAction extends ActionSupport{
String name;
String password;
public String logins(){
System.out.println("in login");
//ActionContext ac = ActionContext.getContext();
HttpServletRequest request=ServletActionContext.getRequest();
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.setAttribute("name", name);
request.setAttribute("password", password);
System.out.println("in login");
if((name!=null)&&(password!=null)){
System.out.println("用户信息已经接受");
System.out.println("用户名为"+name+",密码为:"+password);
return SUCCESS;
}else{
System.out.println("用户名或者密码为空");
return ERROR;
}
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
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">
<session-config>
<session-timeout>0</session-timeout>
</session-config>
<!--把Struts的Action类交给Spring来 管理, 配置spring的监听器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/spring/*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener> <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>/*</url-pattern>
</filter-mapping>
<!--Struts2所有的配置被整合在一个Filter里面,配置Struts2的过滤器 -->
<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>
<error-page>
<error-code>404</error-code>
<location>/page/index.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/page/index.jsp</location>
</error-page>
<welcome-file-list>
<welcome-file>/page/index.jsp</welcome-file>
</welcome-file-list>
</web-app>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="/resources/login.action" method="get">
姓名:<input name="name" type="text"></input><br>
密码:<input name="password" type="password"></input><br>
<input type="submit" value="注册"></input>
</form>
</body>
</html><form action="/resources/login.action" method="get">
Action首字母大写可避免此问题,我的是这样的问题。
木有result
你这个地方
if((name!=null)&&(password!=null)){
System.out.println("用户信息已经接受");
System.out.println("用户名为"+name+",密码为:"+password);
return SUCCESS;
返回SUCCESS这不是扯淡吗。修改成return null;
看上面有木有:
<global-results>
<result name="success">/resources/loginsuccess.jsp</result>
<result name="error">/resources/error.html</result>
</global-results>
这些东西干嘛用的你应该知道吧?