Solved

why my struts can not work?

Posted on 2004-08-12
13
1,530 Views
Last Modified: 2008-01-09
hi,experts,this is my first struts,but it will create error,like this:

500 Servlet Exception
javax.servlet.jsp.JspException: Exception creating bean of class com.beltino.communitymedical.UserForm:
{1}
      at org.apache.struts.taglib.html.FormTag.initFormBean(FormTag.java:563)
      at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:520)
      at _jsp._createuser__jsp._jspService(/createUser.jsp:16)
      at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
      at com.caucho.jsp.Page.pageservice(Page.java:571)
      at com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:155)
      at com.caucho.server.cache.CacheFilterChain.doFilter(CacheFilterChain.java:211)
      at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:177)
      at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:221)
      at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:263)
      at com.caucho.server.port.TcpConnection.run(TcpConnection.java:331)
      at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:464)
      at com.caucho.util.ThreadPool.run(ThreadPool.java:408)
      at java.lang.Thread.run(Thread.java:534)


--------------------------------------------------------------------------------
Resin-3.0.8 (built Tue, 08 Jun 2004 02:25:40 PDT)

--------------------------------------------
this is my jsp page:(createUser.jsp)

<%@ page contentType="text/html;charset=gb2312"%>
<%@ taglib uri="/struts-logic" prefix="logic" %>
<%@ taglib uri="/struts-bean" prefix="bean" %>
<%@ taglib uri="/struts-html" prefix="html" %>
<html:html locale="true">
<head>
<html:base/>
<title>
<bean:message key="index.title"/>
</title>
</head>
<body>
<h2>careate a new</h2>

<html:errors/>
<html:form action="/createUser.do" method="GET">
  userName:<html:text property="user.userName"/><br/>
  password:<html:password property="user.password" /><br/>
  age:<html:text property="user.age" /><br/>
  <html:submit property="submit"/>
</html:form>
</body>
</html:html>

when i not use <html:form></html:form> this can work and in this page can show "crate a new"

why? thanks for help!
0
Comment
Question by:hgbdelphi
  • 9
  • 4
13 Comments
 

Author Comment

by:hgbdelphi
ID: 11781481
this is my struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
   
    <!-- ========== Data Source Configuration =============================== -->
    <data-sources />
   
    <!-- ========== Form Bean Definitions ================================== -->
    <form-beans>
        <form-bean name="userForm" type="com.beltino.communitymedical.UserForm" />
    </form-beans>
   
    <!-- ========== Global Exception Definitions ============================== -->
    <global-exceptions />
   
    <!-- ========== Global Forward Definitions =============================== -->
    <global-forwards>
        <forward name="userCreated" path="/viewUser.jsp" />
    </global-forwards>
   
    <!-- ========== Action Mapping Definitions =============================== -->
    <action-mappings>
        <action
            attribute="userForm"
            input="/createUser.jsp"
            name="userForm"
            scope="request"
            path="/createUser"
            type="com.beltino.communitymedical.UserAction" />
    </action-mappings>
   
    <!-- ========== Controller Configuration ================================ -->
    <controller />
   
    <!-- ========== Message Resources Definitions ============================ -->
   
    <!-- ========== Plug Ins Configuration ================================= -->
    <message-resources parameter="ApplicationResources"/>
</struts-config>

0
 
LVL 35

Expert Comment

by:TimYates
ID: 11781507
And what's the source for com.beltino.communitymedical.UserForm?
0
 

Author Comment

by:hgbdelphi
ID: 11781621
hi,TimYates ,
UserForm:

package com.beltino.communitymedical;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;

/**
 * @author aus
 */
public class UserForm extends ActionForm {
      private User user=new User();
      
      public void setUserName(String userName){
        user.setUserName(userName);
      }
      
      public String getUserName(){
        return user.getUserName();
      }

      /**
       * @return
       */
      public User getUser() {
            return user;
      }

      /**
       * @param user
       */
      public void setUser(User user) {
            this.user = user;
      }
      
      public void reset(ActionMapping mapping,HttpServletRequest request){
        this.user=new User();
      }
      
      public ActionErrors validate(ActionMapping mapping,HttpServletRequest request){
        ActionErrors errors=new ActionErrors();
        if((user.getUserName()==null) || (user.getPassword().length()<3)){
          errors.add("password:",new ActionError("error.user.password"));
        }
        return errors;
      }

}
0
 

Author Comment

by:hgbdelphi
ID: 11781622
UserBean:

package com.beltino.communitymedical;

import com.beltino.util.*;
/**
 * @author aus
 */
public class UserBean {
      
      DBConn dbConn=new DBConn();
      
      public void addUser(User user) throws Exception{
        String sql="";
        sql="insert into TUserRight(RightName,Remark) values('"+user.getUserName()+"','"+user.getPassword()+"')";
        dbConn.executeUpdate(sql);  
      }
      
}
0
 

Author Comment

by:hgbdelphi
ID: 11781627
UserAction:

package com.beltino.communitymedical;

import org.apache.struts.action.*;
import javax.servlet.http.*;
/**
 * @author aus
 */
public class UserAction extends Action{
      public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response){
        UserForm f=(UserForm)form;
        try{
          UserBean bean=new UserBean();
          bean.addUser(f.getUser());
        }catch(Exception e){
          e.printStackTrace();
        }
        request.setAttribute("User",f.getUser());
        return (mapping.findForward("userCreated"));
      }

}
0
 

Author Comment

by:hgbdelphi
ID: 11781629
User:

package com.beltino.communitymedical;

/**
 * @author aus
 */
public class User {
      public String userName;
      public String password;
      public int age;

      /**
       * @return
       */
      public int getAge() {
            return age;
      }

      /**
       * @return
       */
      public String getPassword() {
            return password;
      }

      /**
       * @return
       */
      public String getUserName() {
            return userName;
      }

      /**
       * @param i
       */
      public void setAge(int i) {
            age = i;
      }

      /**
       * @param string
       */
      public void setPassword(String string) {
            password = string;
      }

      /**
       * @param string
       */
      public void setUserName(String string) {
            userName = string;
      }

}
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 35

Expert Comment

by:TimYates
ID: 11781638
<html:form action="/createUser.do" method="GET">

should be:

<html:form action="/createUser" method="GET">

(I think)
0
 

Author Comment

by:hgbdelphi
ID: 11781693
sorry TimYates ,
when i use <html:form action="/createUser" method="GET">,the error is same!

thanks!
0
 

Author Comment

by:hgbdelphi
ID: 11781707
in consle,error is

the import org.apache.struts cannot be resolved
ActionForm cannot be resolved or is not a valid superclass

i cope some jar in my application's  WEB-INF/lib/
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11781722
> i cope some jar in my application's  WEB-INF/lib/

Make sure you have copied ALL the jars from the struts-blank example into your WEB-INF/lib
0
 

Author Comment

by:hgbdelphi
ID: 11782006
yes,i copy all jar in my web-inf/lib
0
 
LVL 35

Accepted Solution

by:
TimYates earned 50 total points
ID: 11782028
can you list the files?

did you try restarting tomcat after you copied them?
0
 

Author Comment

by:hgbdelphi
ID: 11789441
hi,TimYates,now i can use my struts page,i add struts.jar in eclipse's lib,so it can work,but i don't know why this can work,and the *.jar is already in WEB-INF/lib,but i don't add eclipse's lib,when i add it in eclipse lib ,it can work!


  thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: This is the second blog post in a series on email clearinghouses (https://www.xmatters.com/alert-management/blog-email-has-failed-us?utm_campaign=70138000000ydLoAAI&utm_source=exex&utm_medium=article&utm_content=blog-post).   Every month t…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now