初学struts,用struts写一个登录要创建那些文件,怎么写!谢谢了!

BlueAnn 2003-08-25 03:14:53
我知道好象有什么formbean,action,jsp,xml什么的,好象很复杂!
请大家帮忙!
我是初学啊!
...全文
36 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
squallzeng 2003-08-26
  • 打赏
  • 举报
回复
我给你一个例子吧,你可以看一下:(这是一个注册登记的)
JSP页面:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ page import ="com.uniland.dao.*" %>
<%@ page import ="com.uniland.common.*" %>
<%@ page
language="java"
contentType="text/html; charset=GB2312"
pageEncoding="GB2312"
%>
<META http-equiv="Content-Type" content="text/html; charset=GB2312">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="<%=request.getContextPath()%>/theme/Master.css" rel="stylesheet" type="text/css">
<TITLE>用户登录</TITLE>
</HEAD>
<BODY>
<% if (request.getParameter("flag")!=null){
%>
<%if(request.getParameter("flag").equals("55")){%>
<script language="javascript">
alert("您还没有注册,请注册!");
</script>
<%}%>
<%if(request.getParameter("flag").equals("66")){%>
<script language="javascript">
alert("您的密码不正确");
</script>
<%}}%>
<table width="166" border="0" cellspacing="1" cellpadding="0" bgcolor="#33AFF2" align="center">
<tr>
<td bgcolor="#E8F5FE" >
<%Object userid = request.getSession().getAttribute("USER_ID22");
System.out.println(userid);
if(userid!=null && ((String)userid).trim().length()>0){
//userid = CallService.funToChinese(String(userid));
String strTemp = (String)userid;
System.out.println("user=" + userid);

%>
<table width="100%" border="0" cellspacing="2" cellpadding="1" class="unnamed2" >
<tr>
<td align="center">欢迎您:<%=CallService.funToChinese(strTemp)%></td>
</tr>
<tr>
<td align="center"><a href="<%=request.getContextPath()%>/webapps/logout.jsp">注销</a></td>
</tr>
<tr>
<td align="center" bgcolor="#65C2F5"></td>
</tr>
</table>
<%}else {%>
<table width="100%" border="0" cellspacing="2" cellpadding="1" class="unnamed2" >
<html:form action="/UserLog" method="post" >

<tr>
<td align="center">用户账号<input type="text" name="username" size="13"></td>
</tr>
<tr>
<td align="center">用户密码<input type="password" name="password" size="13"></td>
</tr>
<tr>
<td align="center" bgcolor="#65C2F5">
<a href="#" onclick="submit();" class="unnamed2"><img src="<%=request.getContextPath()%>/webapps/images/14_006.gif" width="10" height="10" border="0"> 登录</a>   
<a href="<%=request.getContextPath()%>/webapps/epistemegame/showreg.jsp" onclick="reset();" class="unnamed2"><img src="<%=request.getContextPath()%>/webapps/images/14_006.gif" width="10" height="10" border="0"> 注册</a></td>
</tr>
</html:form>
</table>
<%}%>
</td>
</tr>
</table>
</BODY>
</HTML>
form代码:
package com.uniland.webapps.epistemegame;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.uniland.common.*;
import com.uniland.dao.*;
/**
* Form bean for a Struts application.
* @version 1.0
* @author chenbing
*/
public class UserLogForm extends TaxServiceForm {

public UserLogForm(){

try{
}
catch (Exception e)
{
e.printStackTrace();
}

}

}
action代码:
package com.uniland.webapps.epistemegame;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import java.io.IOException;
import java.io.*;
import com.uniland.dao.*;
import org.apache.commons.beanutils.PropertyUtils;

import com.uniland.common.*;
/**
* @version 1.0
* @author chenbing
*/
public class UserLogFormAction extends Action {

/**
* Constructor
*/
DaoParam sver=new DaoParam();
public boolean addOptionInput( String username,String password)
{
//the check rolecode,and rolename

try{

}
catch (Exception e)
{
return (false);
}
return (true);
}


public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
boolean validated = false;
String username=request.getParameter("username");
String password=request.getParameter("password");
try{
RowSet rs1=new RowSet();
sver.set("SERVICE","SQ0000000015");//连接数据库
sver.set("USER_ID",username);
sver.set("PASSWORD",password);
rs1=CallService.runServiceReturnRowSet(sver,null);
//System.out.println(password);
//System.out.println(rs1.getValue("PASSWORD"));
if(rs1.rowCount()<=0){
return(new ActionForward("/webapps/epistemegame/UserLog.jsp?flag=55"));
}
else if(!password.equals(rs1.getValue("PASSWORD"))){
return(new ActionForward("/webapps/epistemegame/UserLog.jsp?flag=66"));
}
else{
validated=addOptionInput(username,password);
}
}
catch (Exception e)
{
e.printStackTrace();
}
if (validated==true)
{
request.getSession().setAttribute("USER_ID22",username);
return (mapping.findForward("success"));

}
return (new ActionForward(mapping.getInput()));

}

}
struts_comfig.xml
<form-bean name="UserLogForm" type="com.uniland.webapps.epistemegame.UserLogForm">
</form-bean>
<action path="/UserLog" type="com.uniland.webapps.epistemegame.UserLogFormAction" name="UserLogForm" scope="request">
<forward name="success" path="/webapps/epistemegame/preview.jsp">
</forward>
</action>
看看吧,应该对你有帮助的。
还有这个例子你可以看一下:
http://www-900.ibm.com/developerWorks/cn/wsdd/techjournal/0302_fung/fung.shtml
祝你好运!!!!
stonequake 2003-08-26
  • 打赏
  • 举报
回复
我觉得对于初学者来手,还是用ULTRA-EDIT手动编写比较好`~
这样能够了解STRUTS开发模式的来龙去脉,用J8完全是暗箱操作,不利于初学者~~
梦幻圣者 2003-08-26
  • 打赏
  • 举报
回复
按照CSDN上有jb8+struts的例子做做就会了,比较容易入门的。
laverke 2003-08-26
  • 打赏
  • 举报
回复
up
lping468 2003-08-26
  • 打赏
  • 举报
回复
我用JB开发,你应该选择一个适合的工具来做这些事情,要不然麻烦!
joygxd 2003-08-26
  • 打赏
  • 举报
回复
来人指点一下
偶也想学
swj_20 2003-08-26
  • 打赏
  • 举报
回复
老哥,你先找点资料看看,有什么不会再问,CSDN上有jb8+struts的例子,你照着写写就行了,或者看看struts自身的struts-example例子。
cainiao_2000 2003-08-25
  • 打赏
  • 举报
回复
图书
http://www2.borland.com.tw/tw/JBuilder9Struts.pdf
网页:
http://www.cn-java.com/opensource/index.php?page=readsource/Struts.php
http://www.yesky.com/20020820/1626192.shtml
http://www.fawcette.com/china/class.aspx?sort=JSP
guojigang 2003-08-25
  • 打赏
  • 举报
回复
到网上搜一下,有struts的例子,很多软件能自动生成formbean,action。

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧