2个JAVA文件
1、LoginAction
package com.is.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping; import com.is.form.LoginForm; public class LoginAction extends Action
{
private static final long serialVersionUID = 1L; public ActionForward execute
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception { // this line is here for when the input page is upload-utf8.jsp, // it sets the correct character encoding for the response String encoding = request.getCharacterEncoding(); if ((encoding != null) &&
(encoding.equalsIgnoreCase("GB2312")))
{ response.setContentType
("text/html; charset=GB2312"); } else { response.setContentType
("text/html; charset=GBK"); } try { if (form instanceof LoginForm)
{ LoginForm theForm = (LoginForm) form; if(theForm.getUsername().equals("user") && theForm.getPassword().equals("123456"))
{ return new ActionForward("/welcome.do?type=true"); }
else { return new ActionForward("/welcome.do?type=false"); } }
} catch (Exception e)
{ } // this shouldn't happen in this example return null;
}
}
LoginForm.java
package com.is.form;
import org.apache.struts.action.ActionForm;
public class LoginForm extends ActionForm
{
private static final long
serialVersionUID = 1L;
private String username = "";
private String password = "";
/**
* @return Returns the password.
*/
public String getPassword()
{
return password;
} /*** @param password The password to set.
*/
public void setPassword(String password)
{
this.password = password;
}
/**
* @return Returns the username.
*/
public String getUsername()
{
return username;
}
/**
* @param username The username to set.
*/
public void setUsername(String username)
{
this.username = username;
}
}
1、LoginAction
package com.is.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping; import com.is.form.LoginForm; public class LoginAction extends Action
{
private static final long serialVersionUID = 1L; public ActionForward execute
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception { // this line is here for when the input page is upload-utf8.jsp, // it sets the correct character encoding for the response String encoding = request.getCharacterEncoding(); if ((encoding != null) &&
(encoding.equalsIgnoreCase("GB2312")))
{ response.setContentType
("text/html; charset=GB2312"); } else { response.setContentType
("text/html; charset=GBK"); } try { if (form instanceof LoginForm)
{ LoginForm theForm = (LoginForm) form; if(theForm.getUsername().equals("user") && theForm.getPassword().equals("123456"))
{ return new ActionForward("/welcome.do?type=true"); }
else { return new ActionForward("/welcome.do?type=false"); } }
} catch (Exception e)
{ } // this shouldn't happen in this example return null;
}
}
LoginForm.java
package com.is.form;
import org.apache.struts.action.ActionForm;
public class LoginForm extends ActionForm
{
private static final long
serialVersionUID = 1L;
private String username = "";
private String password = "";
/**
* @return Returns the password.
*/
public String getPassword()
{
return password;
} /*** @param password The password to set.
*/
public void setPassword(String password)
{
this.password = password;
}
/**
* @return Returns the username.
*/
public String getUsername()
{
return username;
}
/**
* @param username The username to set.
*/
public void setUsername(String username)
{
this.username = username;
}
}
解决方案 »
- java中 使用sun.net.ftp.FtpClient进行FTP,断网测试,出现问题,求教
- 求一个struts2+jquery+ajax的校验例子,最最最简单即可。
- JNative指针释放问题
- 让人崩溃的spring问题
- 请问一下学习java考什么证书有含金量?
- java jdk 运行一个tcp的聊天程序 出现的问题
- java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration异常
- 关于总重启tomcat解决系统的困惑问题
- Hibernate修改问题
- 何为j2ee?
- 一个500错误信息
- myfaces-extensions.jar在哪里下载 急啊!!!在线等
<?xml version="1.0"?>
<!DOCTYPE struts-config PUBLIC "-
//Apache Software Foundation
//DTD Struts Configuration 1.2//EN"
"http://struts.apache.org/dtds
/struts-config_1_2.dtd">
<struts-config>
<data-sources>
</data-sources>
<form-beans>
<form-bean
name="loginForm"
type="com.is.form.LoginForm"/>
</form-beans>
<global-exceptions>
</global-exceptions>
<global-forwards>
</global-forwards>
<action-mappings>
<action
path="/index"
forward="/index.jsp"/>
<action
path="/welcome"
forward="/welcome.jsp"/>
<action
path="/logincheck"
type="com.is.action.LoginAction"
name="loginForm"
scope="request"
validate="true"/>
</action-mappings>
<controller processorClass=
"org.apache.struts.tiles.TilesRequestProcessor"/>
<message-resources parameter="MessageResources"/>
<plug-in className=
"org.apache.struts.tiles.TilesPlugin">
<set-property property="definitions-config"
value="/WEB-INF/tiles-defs.xml"/>
<set-property property="moduleAware" value="true"/>
</plug-in>
<plug-in className=
"org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/validator-rules.xml,
/WEB-INF/validation.xml"/>
</plug-in>
</struts-config>
<?xml version="1.0" encoding="Shift_JIS"?><!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd"><web-app>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping> <taglib>
<taglib-uri>/tags/struts-bean</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib> <taglib>
<taglib-uri>/tags/struts-html</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib> <taglib>
<taglib-uri>/tags/struts-logic</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib> <taglib>
<taglib-uri>/tags/struts-nested</taglib-uri>
<taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
</taglib> <taglib>
<taglib-uri>/tags/struts-tiles</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib> <!--
<taglib>
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/c.tld</taglib-location>
</taglib> <taglib>
<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/fmt.tld</taglib-location>
</taglib> <taglib>
<taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
<taglib-location>/WEB-INF/sql.tld</taglib-location>
</taglib> <taglib>
<taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
<taglib-location>/WEB-INF/x.tld</taglib-location>
</taglib>
-->
</web-app>
forward="/index.jsp"/>
<action
path="/welcome"
forward="/welcome.jsp"/>
<action
这里的path相对应的。你可以这样改:return new ActionForward("welcome");如果返回字符串是"welcome"的话就挑转到welcome.jsp页面了。。慢慢去理解一下struts-config.xml的配置方法