Solved

why my struts can not work?

Posted on 2004-08-12
13
1,523 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
Comment Utility
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
Comment Utility
And what's the source for com.beltino.communitymedical.UserForm?
0
 

Author Comment

by:hgbdelphi
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 35

Expert Comment

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

should be:

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

(I think)
0
 

Author Comment

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

thanks!
0
 

Author Comment

by:hgbdelphi
Comment Utility
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
Comment Utility
> 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
Comment Utility
yes,i copy all jar in my web-inf/lib
0
 
LVL 35

Accepted Solution

by:
TimYates earned 50 total points
Comment Utility
can you list the files?

did you try restarting tomcat after you copied them?
0
 

Author Comment

by:hgbdelphi
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 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

16 Experts available now in Live!

Get 1:1 Help Now