Solved

why my struts can not work?

Posted on 2004-08-12
13
1,540 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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
 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
constuctor calling other constructor 2 80
java cyclic graphs 15 212
build fail in maven project 11 192
Best practices to work on a spring MVC project 1 126
In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
This article shows the method of using the Resultant Set of Policy Tool to locate Group Policy that applies a particular setting.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

821 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