Action 里面的
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws Exception {
// TODO Auto-generated method stub
String username=request.getParameter("username");
String pass=request.getParameter("pass");
String errmsg ="";
if(username==null ||username.equals(""))
{
errmsg +="您的用户名丢失或者没有输入,请重新输入";
}
else if(pass==null ||pass.equals(""))
{
errmsg +="您的密码丢失或者没有输入,请重新输入";
}
else
{
try
{
DbDao dd=DbDao.instance("com.mysql.jdbc.Driver","jdbc:mysql://localhost:3306/xtq","root","32147");
ResultSet rs=(ResultSet) dd.query("select password from user_table where username='" + username + "'");
if(rs.next())
{
if(rs.getString("password").equals(pass))
{
HttpSession session=request.getSession(true);//新建一个HttpSession Session是一个作用域相当于一个容器 http://topic.csdn.net/t/20051126/23/4420622.html Session是WEB应用程序的作用域,一般来说可以看作一个浏览器就是一个Session。Session是一个容器,用于保存一些变量以及对象,使这些变量以及对象在Session域中传输。
session.setAttribute("name", username);//保存username比如你在aa.jsp中 session.setAttribute("session1","这是保存的内容");那你在bb.jsp中可以String str=(String)session.getAttrinbute("session1");//那么str就等于"这是保存的内容"
return mapping.findForward("welcome");
}
else
{
errmsg +="您的用户名和密码不符合,请重新输入";
}
}
else
{
errmsg +="您的用户名不存在,请先注册";
}
}
catch (Exception e)
{
request.setAttribute("exception", "业务异常");
return mapping.findForward("error");
}
}
if(errmsg!=null ||!errmsg.equals(""))
{
request.setAttribute("err", errmsg);
return mapping.findForward("input");
}
else
{
return mapping.findForward("welcome");
}
}
JSP页面的“登陆”按钮通过Action里面的execute判断然后跳转页面 这个是怎么做的??
那个按钮要怎么写 还是要在配置文件里面配?
请教了 我是大菜鸟
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws Exception {
// TODO Auto-generated method stub
String username=request.getParameter("username");
String pass=request.getParameter("pass");
String errmsg ="";
if(username==null ||username.equals(""))
{
errmsg +="您的用户名丢失或者没有输入,请重新输入";
}
else if(pass==null ||pass.equals(""))
{
errmsg +="您的密码丢失或者没有输入,请重新输入";
}
else
{
try
{
DbDao dd=DbDao.instance("com.mysql.jdbc.Driver","jdbc:mysql://localhost:3306/xtq","root","32147");
ResultSet rs=(ResultSet) dd.query("select password from user_table where username='" + username + "'");
if(rs.next())
{
if(rs.getString("password").equals(pass))
{
HttpSession session=request.getSession(true);//新建一个HttpSession Session是一个作用域相当于一个容器 http://topic.csdn.net/t/20051126/23/4420622.html Session是WEB应用程序的作用域,一般来说可以看作一个浏览器就是一个Session。Session是一个容器,用于保存一些变量以及对象,使这些变量以及对象在Session域中传输。
session.setAttribute("name", username);//保存username比如你在aa.jsp中 session.setAttribute("session1","这是保存的内容");那你在bb.jsp中可以String str=(String)session.getAttrinbute("session1");//那么str就等于"这是保存的内容"
return mapping.findForward("welcome");
}
else
{
errmsg +="您的用户名和密码不符合,请重新输入";
}
}
else
{
errmsg +="您的用户名不存在,请先注册";
}
}
catch (Exception e)
{
request.setAttribute("exception", "业务异常");
return mapping.findForward("error");
}
}
if(errmsg!=null ||!errmsg.equals(""))
{
request.setAttribute("err", errmsg);
return mapping.findForward("input");
}
else
{
return mapping.findForward("welcome");
}
}
JSP页面的“登陆”按钮通过Action里面的execute判断然后跳转页面 这个是怎么做的??
那个按钮要怎么写 还是要在配置文件里面配?
请教了 我是大菜鸟
那个按钮要怎么写 还是要在配置文件里面配?首先你想问什么?JSP页面的“登陆”按钮通过Action里面的execute判断然后跳转页面 这个是怎么做的??
程序里不是已经写转发了 mapping.findForward("input"); 他就实现了跳转
而你跳转的页面 需要在xml文件里配置 input是名字 后面要有跳转的页面
那个按钮要怎么写?
写个form表单 提交到action啊
谢谢
attribute="testFileForm"
name="testFileForm"
parameter="method"
path="/xxx"
scope="request"
type="com.tx.jygl.report.btwj.action.TestFileAction" >
<forward name="error" path="/error.jsp" /> //按照不同的结果返回不同的页面
<forward name="welcome" path="/welcome.jsp" />
</action>
这位仁兄说得够明白了,只不过没有说struts-config.xml的配置,你要把你的action和Form在这个配置文件中配置下,还有mapping.findForward("input"); 这里的“input”也要配置下
里面这些都配了 我就是不知道 jsp上的按钮 要怎么跟Action挂上钩
哇,你到底有没有学过java啊,看下Struts教程中的Hello Word 程序,保证你自己可以搞定
首先是按钮中写一个javascript事件:
<input type = "button" value = "提交" onclick = "sub()">
然后写javascript:
<javascrip>
function sub(){
document.forms[0].submit();
}
</javascrip>
<input type="submit" value="提交按钮">
</form>楼主你在不会 我就真没办法了