MVC mode in JSP-network dating (2) problems ......

Source: Internet
Author: User

The servlet object cannot be found ...... Which of the following experts will give you some advice ...... (A problem occurs when you submit the application after registration)

2. JavaBean and Servlet Management

In this system, the package names of the JavaBean class are mybean. Data, And the servlet package names are myservlet. Control.

Copy the bytecode of the JavaBean class and Servlet class to D:/tomcat 6.0/webapps/mkfriend/WEB-INF/classes/mybean/Data

And D:/tomcat 6.0/webapps/mkfriend/WEB-INF/classes/myservlet/Control in

3. Configuration File

Directory: D:/tomcat 6.0/webapps/mkfriend/WEB-INF

Web. xml

<? XML version = "1.0" encoding = "ISO-8859-1"?>
<Web-app>
<Servlet>
<Servlet-Name> register </servlet-Name>
<Servlet-class> myservlet. Control. handleregister </servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-Name> register </servlet-Name>
<URL-pattern>/helpregister> </url-pattern>
</Servlet-mapping>
<Servlet>
<Servlet-Name> login </servlet-Name>
<Servlet-class> myservlet. Control. handlelogin </servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-Name> login </servlet-Name>
<URL-pattern>/helplogin </url-pattern>
</Servlet-mapping>
<Servlet>
<Servlet-Name> upload </servlet-Name>
<Servlet-class> myservlet. Control. handleupload </servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-Name> upload </servlet-Name>
<URL-pattern>/helpupload> </url-pattern>
</Servlet-mapping> <servlet>
<Servlet-Name> lookrecord </servlet-Name>
<Servlet-class> myservlet. Control. handledatabase </servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-Name> lookrecord </servlet-Name>
<URL-pattern>/helpshowmember> </url-pattern>
</Servlet-mapping>
<Servlet>
<Servlet-Name> modifypassword </servlet-Name>
<Servlet-class> myservlet. Control. handlepassword </servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-Name> modifypassword </servlet-Name>
<URL-pattern>/helpmodifypassword> </url-pattern>
</Servlet-mapping>
<Servlet>
<Servlet-Name> modifyoldmess </servlet-Name>
<Servlet-class> myservlet. Control. handlemodifymess </servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-Name> modifyoldmess </servlet-Name>
<URL-pattern>/helpmodifymess> </url-pattern>
</Servlet-mapping>
<Servlet>
<Servlet-Name> exit </servlet-Name>
<Servlet-class> myservlet. Control. handleexit </servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-Name> exit </servlet-Name>
<URL-pattern>/helpexitlogin> </url-pattern>
</Servlet-mapping>
</Web-app>

Member registration

I. Model (JavaBean)

Register. Java describes user registration information

Package mybean. Data;
Public class register {
String LOGNAME = "", password = "", email = "", phone = "", message = "";
String backnews;
Public void setlogname (string name ){
LOGNAME = Name;
}
Public String getlogname (){
Return LOGNAME;
}
Public void setpassword (string PW ){
Password = pw;
}
Public String GetPassword (){
Return password;
}
Public void setemail (string em ){
Email = em;
}
Public String getemail (){
Return email;
}
Public void setphone (string pH ){
Phone = Ph;
}
Public String getphone (){
Return phone;
}
Public void setmessage (string m ){
Message = m;
}
Public String getmessage (){
Return message;
}
Public void setbacknews (string s ){
Backnews = s;
}
Public String getbacknews (){
Return backnews;
}
}

Ii. Controller (servlet)

Handleregister. Java

Package myservlet. Control;
Import mybean. Data .*;
Import java. SQL .*;
Import java. Io .*;
Import javax. servlet .*;
Import javax. servlet. http .*;
Public class handleregister extends httpservlet {
Public void Init (servletconfig config) throws servletexception {
Super. INIT (config );
Try {
Class. forname ("com. Microsoft. sqlserver. JDBC. sqlserverdriver ");
} Catch (exception e ){}
}
Public String handlestring (string s ){
Try {
Byte BB [] = S. getbytes ("ISO-8859-1 ");
S = new string (bb );
}
Catch (exception ee ){}
Return S;
}
Public void dopost (httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {
Connection con;
Statement SQL;
Register Reg = new register ();
Request. setattribute ("register", Reg );
String LOGNAME = request. getparameter ("LOGNAME"). Trim (),
Password = request. getparameter ("password"). Trim (),
Email = request. getparameter ("email"). Trim (),
Phone = request. getparameter ("phone"). Trim (),
Message = request. getparameter ("message ");
String uri = "JDBC: sqlserver: // 127.0.0.1: 1433; databasename = makefriend ";
If (LOGNAME = NULL)
LOGNAME = "";
If (Password = NULL)
Password = "";
Boolean isld = true;
For (INT I = 0; I <LOGNAME. Length (); I ++ ){
Char c = LOGNAME. charat (I );
If (! (C <= 'Z' & C> = 'A') | (C <= 'Z' & C> = 'A ') | (C <= '9' & C> = '0 ')))
Isld = false;
}
Boolean boo = LOGNAME. Length ()> 0 & password. Length ()> 0 & isld;
String backnews = "";
Try {
LOGNAME = handlestring (LOGNAME );
Password = handlestring (password );
Phone = handlestring (phone );
Email = handlestring (email );
Message = handlestring (Message );
String PIC = "public.jpg ";
String insertrecord = "('" + LOGNAME + "', '" + password + "', '" + phone + "', '" + email + "', '"+ message +"', '"+ PIC + "')";
Con = drivermanager. getconnection (Uri, "sa", "sa ");
String insertcondition = "insert into Member values" + insertrecord;
SQL = con. createstatement ();
If (BOO ){
Int m= SQL .exe cuteupdate (insertcondition );
If (M! = 0 ){
Backnews = "registration successful ";
Reg. setbacknews (backnews );
Reg. setlogname (LOGNAME );
Reg. setpassword (password );
Reg. setphone (phone );
Reg. setemail (email );
Reg. setmessage (Message );
}
}
Else {
Backnews = "the information is incomplete or the name contains invalid characters ";
Reg. setbacknews (backnews );
}
Con. Close ();
}
Catch (sqlexception exp ){
Backnews = "This member name has been used. Please change the name ";
Reg. setbacknews (backnews );
}
Requestdispatcher dispatcher = request. getrequestdispatcher ("showregistermess. jsp ");
Dispatcher. Forward (request, response );
}
Public void doget (httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {
Dopost (request, response );
}
}
3. View (JSP)

Register. jsp Registration Information Page

<% @ Page contenttype = "text/html; charset = gb2312" %>
<Head> <% @ include file = "head.txt" %> <HTML> <body bgcolor = cyan> <font size = 2>
<Center> <form action = "helpregister" name = form method = post>
<Table>
Enter your information. The member name must consist of letters and numbers.
<Tr> <TD> member name: </TD> <input type = text name = "LOGNAME"> * </TD> </tr>
<Tr> <TD> set password: </TD> <input type = password name = "LOGNAME"> * </TD> </tr>
<Tr> <TD> Email: </TD> <input type = text name = "email"> * </TD> </tr>
<Tr> <TD> contact number: </TD> <input type = text name = "phone"> * </TD> </tr>
</Table>
<Table>
<Tr> <TD> <font size = 2> enter your resume and dating criteria: </TD> </tr>
<Tr> <TD> <textarea name = "message" rows = "6" Cols = "30"> </textarea> </TD> </tr>
<Tr> <TD> <input type = submit name = "G" value = "Submit"> </TD> </tr>
</Table> </form> </center> </body>

Showregistermess. jsp

<% @ Page contenttype = "text/html; charset = gb2312" %>
<% @ Page import = "mybean. Data. Register" %>
<JSP: usebean id = "register" type = "mybean. Data. Register" Scope = "request"/>
<Head> <% @ include file = "head.txt" %> <HTML> <body bgcolor = cyan>
<Center>
<Font size = 4 color = blue>
<Br> <JSP: getproperty name = "register" property = "backnews"/>
</Font>
<Table>
<Tr> <TD> registered member name: </TD>
<TD> <JSP: getproperty name = "register" property = "LOGNAME"/> </TD>
</Tr>
<Tr> <TD> registered member Email: </TD>
<TD> <JSP: getproperty name = "register" property = "phone"/> </TD>
</Tr>
</Table> <tr> <TD> your resume and dating standards: </TD> </tr>
<Tr> <TD> <textarea name = "message" rows = "6" Cols = "30">
<JSP: getproperty name = "register" property = "message"/>
</Textarea>
</TD> </tr> </table> </center> </body>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.