Struts1.2 + Spring2.5 + Hibernate3.2 framework of the structure (b)

2010-03-26  来源:本站原创  分类:Java  人气:185 

register.jsp Code

<% @ Page language = "java" import = "java.util .*" pageEncoding = "UTF-8"%>

"%

String path = request.getContextPath ();

String basePath = request.getScheme () + "://"

+ Request.getServerName () + ":" + request.getServerPort ()

+ Path + "/";

% "

<! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.01 Transitional / / EN">

<html>

<head>

<base href = "<% = basePath%>">

<title> My JSP 'register.jsp' starting page </ 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>

SSH build the framework of testing - Registration.

<br>

<form action = "<% = request.getContextPath ()%> / login.do? methods = register"

method = "post">

<input type= "text" name= "username">

<br />

<input type= "password" name= "password">

<br />

<input type= "submit" value= " Registration " "

<input type = "button" value = "Back"

onclick = "window.location.href = '<% = request.getContextPath ()%> / login.jsp'">

</ form>

</ body>

</ html>

2.5. Modify the Action class

Operation: Add login and register two methods, which register class before you add the empty Hibernate, etc. after the rewrite, login method for the detection of the first struts is added successfully detected only in the service end users: zhoulukang password: 123 user login.

/ *

* Generated by MyEclipse Struts

* Template path: templates / java / JavaClass.vtl

* /

package com.zlk.struts.action;

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionForward;

import org.apache.struts.action.ActionMapping;

import org.apache.struts.actions.DispatchAction;

import com.zlk.struts.form.LoginForm;

/ **

* MyEclipse Struts

* Creation date: 03-05-2010

*

* XDoclet definition:

* @ Struts.action path = "/ login" name = "loginForm" parameter = "methods" scope = "request" validate = "true"

* /

public class LoginAction extends DispatchAction (

/ *

* Generated Methods

* /

/ **

* Landing approach

* /

public ActionForward login (ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response) (

LoginForm loginForm = (LoginForm) form; / / TODO Auto-generated method stub

response.setContentType ( "text / html; charset = UTF-8");

PrintWriter out = null;

try (

out = response.getWriter ();

if (loginForm.getUsername (). equals ( "zhoulukang") & & loginForm.getPassword (). equals ( "123")) (

out.print ( "<font color='red'>" + loginForm.getUsername ()+"</ font> Congratulations on the success of your landing! ");

) Else (

out.println ( "Sorry, login failed");

)

) Catch (IOException e) (

/ / TODO Auto-generated catch block

e.printStackTrace ();

)

return null;

)

/ **

* Registration method

* /

public ActionForward register (ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response) (

LoginForm loginForm = (LoginForm) form; / / TODO Auto-generated method stub

return null;

)

)

2.6. Test struts framework

Action: Enter the user name password

Struts1.2 + Spring2.5 + Hibernate3.2 framework of the structure (b)

Operation: Click Login

Struts1.2 + Spring2.5 + Hibernate3.2 framework of the structure (b)

相关文章